diff --git a/LHScans/plot_LLScan.py b/LHScans/plot_LLScan.py index d1d54d3..e4a6f66 100644 --- a/LHScans/plot_LLScan.py +++ b/LHScans/plot_LLScan.py @@ -157,7 +157,7 @@ def BuildScan(scan, param, files, color, yvals, ycut): resultsXS_data = {} resultsXS_asimov = {} -if opt.OBSNAME=='mass4l': +if opt.OBSNAME.startswith('mass4l'): resultsXS_data_v2 = {} resultsXS_asimov_v2 = {} if opt.V4: @@ -181,19 +181,25 @@ def BuildScan(scan, param, files, color, yvals, ycut): doubleDiff = False if(obsName == 'mass4l'): label = 'm_{4l}' -elif(obsName == 'rapidity4l'): label = '|y_{H}|' +elif(obsName == 'mass4l_zzfloating'): label = 'm_{4l}' +elif(obsName == 'njets_pt30_eta4p7'): label = 'N_{jet}, pT>30 GeV, |#eta|<4.7' elif(obsName == 'pT4l'): label = 'p_{T}^{H} (GeV)' -elif(obsName == 'massZ1'): label = 'm_{Z1} (GeV)' -elif(obsName == 'massZ2'): label = 'm_{Z2} (GeV)' -elif(obsName == 'njets_pt30_eta2p5'): label = 'nJets, pT>30 GeV, |#eta|<2.5' -elif(obsName == 'pTj1'): label = 'p_{T}^{(j1, 2.5)} (GeV)' -elif(obsName == 'pTj1_eta4p7'): label = 'p_{T}^{(j1, 4.7)} (GeV)' -elif(obsName == 'mass4l'): label = 'm_{4\ell} (GeV)' -elif(obsName == 'costhetastar'): label = 'cos(#theta^{*})' +elif(obsName == 'rapidity4l'): label = '|y_{H}|' elif(obsName == 'costhetaZ1'): label = 'cos(#theta_{1})' elif(obsName == 'costhetaZ2'): label = 'cos(#theta_{2})' -elif(obsName == 'phistar'): label = '#Phi^{#star}' elif(obsName == 'phi'): label = '#Phi' +elif(obsName == 'phistar'): label = '#Phi^{#star}' +elif(obsName == 'costhetastar'): label = 'cos(#theta^{*})' +elif(obsName == 'massZ1'): label = 'm_{Z1} (GeV)' +elif(obsName == 'massZ2'): label = 'm_{Z2} (GeV)' +elif(obsName == 'pTj1'): label = 'p_{T}^{(j1, 4.7)} (GeV)' +elif(obsName == 'pTHj'): label = 'p_{T}^{Hj} (GeV)' +elif(obsName == 'mHj'): label = 'm_{Hj} (GeV)' +elif(obsName == 'pTj2'): label = 'p_{T}^{(j2, 4.7)} (GeV)' +elif(obsName == 'mjj'): label = 'm_{jj} (GeV)' +elif(obsName == 'absdetajj'): label = '|#Delta#Eta_{jj}|' +elif(obsName == 'dphijj'): label = '|#Delta#Phi_{jj}|' +elif(obsName == 'pTHjj'): label = 'p_{T}^{Hjj} (GeV)' elif(obsName == 'TCjmax'): label = '#mathscr{T}_{#mathscr{C},{j}}' elif(obsName == 'TBjmax'): label = '#mathscr{T}_{#mathscr{B},{j}}' elif(obsName == 'D0m'): label = 'D_{0m}' @@ -201,48 +207,18 @@ def BuildScan(scan, param, files, color, yvals, ycut): elif(obsName == 'D0hp'): label = 'D_{0h^{+}}' elif(obsName == 'Dint'): label = 'D_{int}' elif(obsName == 'DL1'): label = 'D_{#Lambda1}' -elif(obsName == 'pTHj'): label = 'p_{T}^{Hj} (GeV)' -elif(obsName == 'massZ1 vs massZ2'): - obsName_tmp = obsName.split(' vs ') - obsName = obsName_tmp[0]+"_"+obsName_tmp[1] - label = 'm_{Z1} (GeV)' - label_2nd = 'm_{Z2} (GeV)' - doubleDiff = True -elif(obsName == 'njets_pt30_eta2p5 vs pTHj'): - obsName_tmp = obsName.split(' vs ') - obsName = obsName_tmp[0]+"_"+obsName_tmp[1] - label = 'N_{jet}' - label_2nd = 'p_{T}^{Hj} (GeV)' - doubleDiff = True -elif(obsName == 'njets_pt30_eta2p5 vs pT4l'): - obsName_tmp = obsName.split(' vs ') - obsName = obsName_tmp[0]+"_"+obsName_tmp[1] - label = 'N_{jet}' - label_2nd = 'p_{T}^{H} (GeV)' - doubleDiff = True +elif(obsName == 'DL1Zg'): label = 'D_{#Lambda1}_{Zg}' elif(obsName == 'rapidity4l vs pT4l'): obsName_tmp = obsName.split(' vs ') obsName = obsName_tmp[0]+"_"+obsName_tmp[1] label = '|y_{H}|' label_2nd = 'p_{T}^{H} (GeV)' doubleDiff = True -elif(obsName == 'njets_pt30_eta2p5 vs mjj'): - obsName_tmp = obsName.split(' vs ') - obsName = obsName_tmp[0]+"_"+obsName_tmp[1] - label = 'N_{jet}' - label_2nd = 'm_{jj} (GeV)' - doubleDiff = True -elif(obsName == 'njets_pt30_eta2p5 vs mHjj'): - obsName_tmp = obsName.split(' vs ') - obsName = obsName_tmp[0]+"_"+obsName_tmp[1] - label = 'N_{jet}' - label_2nd = 'm_{Hjj} (GeV)' - doubleDiff = True -elif(obsName == 'njets_pt30_eta2p5 vs mHj'): +elif(obsName == 'njets_pt30_eta4p7 vs pT4l'): obsName_tmp = obsName.split(' vs ') obsName = obsName_tmp[0]+"_"+obsName_tmp[1] label = 'N_{jet}' - label_2nd = 'm_{Hj} (GeV)' + label_2nd = 'p_{T}^{H} (GeV)' doubleDiff = True elif(obsName == 'pTj1 vs pTj2'): obsName_tmp = obsName.split(' vs ') @@ -250,43 +226,27 @@ def BuildScan(scan, param, files, color, yvals, ycut): label = 'p_{T}^{j,1} (GeV)' label_2nd = 'p_{T}^{j,2} (GeV)' doubleDiff = True -elif(obsName == 'njets_pt30_eta2p5 vs TCjmax'): - obsName_tmp = obsName.split(' vs ') - obsName = obsName_tmp[0]+"_"+obsName_tmp[1] - label = 'N_{jet}' - label_2nd = 'T_{Cj} (GeV)' - doubleDiff = True -elif(obsName == 'njets_pt30_eta2p5 vs TBjmax'): - obsName_tmp = obsName.split(' vs ') - obsName = obsName_tmp[0]+"_"+obsName_tmp[1] - label = 'N_{jet}' - label_2nd = 'T_{Bj} (GeV)' - doubleDiff = True -elif(obsName == 'njets_pt30_eta2p5 vs pTj2'): - obsName_tmp = obsName.split(' vs ') - obsName = obsName_tmp[0]+"_"+obsName_tmp[1] - label = 'N_{jet}' - label_2nd = 'p_{T}^{j,2} (GeV)' - doubleDiff = True -elif(obsName == 'pT4l vs pTj1'): +elif(obsName == 'pT4l vs pTHj'): obsName_tmp = obsName.split(' vs ') obsName = obsName_tmp[0]+"_"+obsName_tmp[1] label = 'p_{T}^{H} (GeV)' - label_2nd = 'p_{T}^{j,1} (GeV)' + label_2nd = 'p_{T}^{Hj} (GeV)' doubleDiff = True -elif(obsName == 'njets_pt30_eta2p5 vs pTj1'): +elif(obsName == 'massZ1 vs massZ2'): obsName_tmp = obsName.split(' vs ') obsName = obsName_tmp[0]+"_"+obsName_tmp[1] - label = 'N_{jet} (2.5)' - label_2nd = 'p_{T}^{j,1} (GeV)' + label = 'm_{Z1} (GeV)' + label_2nd = 'm_{Z2} (GeV)' doubleDiff = True -elif(obsName == 'njets_pt30_eta4p7 vs pTj1_eta4p7'): +elif(obsName == 'TCjmax vs pT4l'): obsName_tmp = obsName.split(' vs ') obsName = obsName_tmp[0]+"_"+obsName_tmp[1] - label = 'N_{jet} (4.7)' - label_2nd = 'p_{T}^{j,1} (GeV)' + label = '#mathscr{T}_{#mathscr{C},{j}} (GeV)' + label_2nd = 'p_{T}^{H} (GeV)' doubleDiff = True + + sys.path.append('../inputs') _temp = __import__('inputs_sig_'+obsName+'_'+opt.YEAR, globals(), locals(), ['observableBins'], -1) obs_bins = _temp.observableBins @@ -294,7 +254,7 @@ def BuildScan(scan, param, files, color, yvals, ycut): nBins = len(obs_bins) if not doubleDiff: nBins = nBins-1 #in case of 1D measurement the number of bins is -1 the length of the list of bin boundaries -if obsName=='mass4l': nBins = nBins + 3 #in case of mass4l len(obs_bins)=1, we need to add +3 for cross section in the three different final states +if obsName.startswith("mass4l"): nBins = nBins + 3 #in case of mass4l len(obs_bins)=1, we need to add +3 for cross section in the three different final states if v4_flag: nBins = (len(obs_bins)-1)*2 @@ -302,7 +262,7 @@ def BuildScan(scan, param, files, color, yvals, ycut): _bin = i _obs_bin = _poi+str(i) - if obsName == 'mass4l': + if obsName.startswith("mass4l"): if _bin == 1: _obs_bin = 'r2e2muBin0' if _bin == 2: @@ -339,7 +299,7 @@ def BuildScan(scan, param, files, color, yvals, ycut): graphs[ifile].SetPoint(ipoint,entry.SigmaBin0,2.0*entry.deltaNLL) ipoint = ipoint+1 elif _bin == 1: - if obsName == 'mass4l': + if obsName.startswith("mass4l"): graphs[ifile].SetPoint(ipoint,entry.r2e2muBin0,2.0*entry.deltaNLL) elif v4_flag: graphs[ifile].SetPoint(ipoint,entry.r4lBin0,2.0*entry.deltaNLL) @@ -347,7 +307,7 @@ def BuildScan(scan, param, files, color, yvals, ycut): graphs[ifile].SetPoint(ipoint,entry.SigmaBin1,2.0*entry.deltaNLL) ipoint = ipoint+1 elif _bin == 2: - if obsName == 'mass4l': + if obsName.startswith("mass4l"): graphs[ifile].SetPoint(ipoint,entry.r4muBin0,2.0*entry.deltaNLL) elif v4_flag: graphs[ifile].SetPoint(ipoint,entry.r2e2muBin1,2.0*entry.deltaNLL) @@ -355,7 +315,7 @@ def BuildScan(scan, param, files, color, yvals, ycut): graphs[ifile].SetPoint(ipoint,entry.SigmaBin2,2.0*entry.deltaNLL) ipoint = ipoint+1 elif _bin == 3: - if obsName == 'mass4l': + if obsName.startswith("mass4l"): graphs[ifile].SetPoint(ipoint,entry.r4eBin0,2.0*entry.deltaNLL) elif v4_flag: graphs[ifile].SetPoint(ipoint,entry.r4lBin1,2.0*entry.deltaNLL) @@ -399,16 +359,76 @@ def BuildScan(scan, param, files, color, yvals, ycut): graphs[ifile].SetPoint(ipoint,entry.SigmaBin9,2.0*entry.deltaNLL) ipoint = ipoint+1 elif _bin == 10: - graphs[ifile].SetPoint(ipoint,entry.SigmaBin10,2.0*entry.deltaNLL) + if v4_flag: + graphs[ifile].SetPoint(ipoint,entry.r2e2muBin5,2.0*entry.deltaNLL) + else: + graphs[ifile].SetPoint(ipoint,entry.SigmaBin10,2.0*entry.deltaNLL) ipoint = ipoint+1 elif _bin == 11: - graphs[ifile].SetPoint(ipoint,entry.SigmaBin11,2.0*entry.deltaNLL) + if v4_flag: + graphs[ifile].SetPoint(ipoint,entry.r4lBin5,2.0*entry.deltaNLL) + else: + graphs[ifile].SetPoint(ipoint,entry.SigmaBin11,2.0*entry.deltaNLL) ipoint = ipoint+1 elif _bin == 12: - graphs[ifile].SetPoint(ipoint,entry.SigmaBin12,2.0*entry.deltaNLL) + if v4_flag: + graphs[ifile].SetPoint(ipoint,entry.r2e2muBin6,2.0*entry.deltaNLL) + else: + graphs[ifile].SetPoint(ipoint,entry.SigmaBin12,2.0*entry.deltaNLL) + ipoint = ipoint+1 + elif _bin == 13: + if v4_flag: + graphs[ifile].SetPoint(ipoint,entry.r4lBin6,2.0*entry.deltaNLL) + else: + graphs[ifile].SetPoint(ipoint,entry.SigmaBin12,2.0*entry.deltaNLL) + ipoint = ipoint+1 + elif _bin == 14: + if v4_flag: + graphs[ifile].SetPoint(ipoint,entry.r2e2muBin7,2.0*entry.deltaNLL) + else: + graphs[ifile].SetPoint(ipoint,entry.SigmaBin13,2.0*entry.deltaNLL) + ipoint = ipoint+1 + elif _bin == 15: + if v4_flag: + graphs[ifile].SetPoint(ipoint,entry.r4lBin7,2.0*entry.deltaNLL) + else: + graphs[ifile].SetPoint(ipoint,entry.SigmaBin14,2.0*entry.deltaNLL) + ipoint = ipoint+1 + elif _bin == 16: + if v4_flag: + graphs[ifile].SetPoint(ipoint,entry.r2e2muBin8,2.0*entry.deltaNLL) + else: + graphs[ifile].SetPoint(ipoint,entry.SigmaBin15,2.0*entry.deltaNLL) + ipoint = ipoint+1 + elif _bin == 17: + if v4_flag: + graphs[ifile].SetPoint(ipoint,entry.r4lBin8,2.0*entry.deltaNLL) + else: + graphs[ifile].SetPoint(ipoint,entry.SigmaBin16,2.0*entry.deltaNLL) ipoint = ipoint+1 - else: - graphs[ifile].SetPoint(ipoint,entry.SigmaBin13,2.0*entry.deltaNLL) + elif _bin == 18: + if v4_flag: + graphs[ifile].SetPoint(ipoint,entry.r2e2muBin9,2.0*entry.deltaNLL) + else: + graphs[ifile].SetPoint(ipoint,entry.SigmaBin17,2.0*entry.deltaNLL) + ipoint = ipoint+1 + elif _bin == 19: + if v4_flag: + graphs[ifile].SetPoint(ipoint,entry.r4lBin9,2.0*entry.deltaNLL) + else: + graphs[ifile].SetPoint(ipoint,entry.SigmaBin17,2.0*entry.deltaNLL) + ipoint = ipoint+1 + elif _bin == 20: + if v4_flag: + graphs[ifile].SetPoint(ipoint,entry.r2e2muBin10,2.0*entry.deltaNLL) + else: + graphs[ifile].SetPoint(ipoint,entry.SigmaBin18,2.0*entry.deltaNLL) + ipoint = ipoint+1 + elif _bin == 21: + if v4_flag: + graphs[ifile].SetPoint(ipoint,entry.r4lBin10,2.0*entry.deltaNLL) + else: + graphs[ifile].SetPoint(ipoint,entry.SigmaBin18,2.0*entry.deltaNLL) ipoint = ipoint+1 c=TCanvas("c", "c", 1000, 800) @@ -435,15 +455,27 @@ def BuildScan(scan, param, files, color, yvals, ycut): graphs[0].Draw("AC") if v4_flag: if _bin == 0: xtitle = "#sigma_{bin 2e2mu 0}" - if _bin == 1: xtitle = "#sigma_{bin 4l 0}" - if _bin == 2: xtitle = "#sigma_{bin 2e2mu 1}" - if _bin == 3: xtitle = "#sigma_{bin 4l 1}" - if _bin == 4: xtitle = "#sigma_{bin 2e2mu 2}" - if _bin == 5: xtitle = "#sigma_{bin 4l 2}" - if _bin == 6: xtitle = "#sigma_{bin 2e2mu 3}" - if _bin == 7: xtitle = "#sigma_{bin 4l 3}" - if _bin == 8: xtitle = "#sigma_{bin 2e2mu 4}" - if _bin == 9: xtitle = "#sigma_{bin 4l 4}" + elif _bin == 1: xtitle = "#sigma_{bin 4l 0}" + elif _bin == 2: xtitle = "#sigma_{bin 2e2mu 1}" + elif _bin == 3: xtitle = "#sigma_{bin 4l 1}" + elif _bin == 4: xtitle = "#sigma_{bin 2e2mu 2}" + elif _bin == 5: xtitle = "#sigma_{bin 4l 2}" + elif _bin == 6: xtitle = "#sigma_{bin 2e2mu 3}" + elif _bin == 7: xtitle = "#sigma_{bin 4l 3}" + elif _bin == 8: xtitle = "#sigma_{bin 2e2mu 4}" + elif _bin == 9: xtitle = "#sigma_{bin 4l 4}" + elif _bin == 10: xtitle = "#sigma_{bin 2e2mu 5}" + elif _bin == 11: xtitle = "#sigma_{bin 4l 5}" + elif _bin == 12: xtitle = "#sigma_{bin 2e2mu 6}" + elif _bin == 13: xtitle = "#sigma_{bin 4l 6}" + elif _bin == 14: xtitle = "#sigma_{bin 2e2mu 7}" + elif _bin == 15: xtitle = "#sigma_{bin 4l 7}" + elif _bin == 16: xtitle = "#sigma_{bin 2e2mu 8}" + elif _bin == 17: xtitle = "#sigma_{bin 4l 8}" + elif _bin == 18: xtitle = "#sigma_{bin 2e2mu 9}" + elif _bin == 19: xtitle = "#sigma_{bin 4l 9}" + elif _bin == 20: xtitle = "#sigma_{bin 2e2mu 10}" + elif _bin == 21: xtitle = "#sigma_{bin 4l 10}" else: xtitle = "#sigma_{bin " + str(_bin) + "}" graphs[0].GetXaxis().SetTitle(xtitle) @@ -537,6 +569,18 @@ def BuildScan(scan, param, files, color, yvals, ycut): if _bin == 7: exp_fit = 'Exp. #sigma_{bin, 4l, 3} = %.2f^{#plus %.2f}_{#minus %.2f} (stat)^{#plus %.2f}_{#minus %.2f} (syst)' % (exp_nom[0], exp_nom_stat[1], abs(exp_nom_stat[2]), exp_up_sys, exp_do_sys) if _bin == 8: exp_fit = 'Exp. #sigma_{bin, 2e2mu, 4} = %.2f^{#plus %.2f}_{#minus %.2f} (stat)^{#plus %.2f}_{#minus %.2f} (syst)' % (exp_nom[0], exp_nom_stat[1], abs(exp_nom_stat[2]), exp_up_sys, exp_do_sys) if _bin == 9: exp_fit = 'Exp. #sigma_{bin, 4l, 4} = %.2f^{#plus %.2f}_{#minus %.2f} (stat)^{#plus %.2f}_{#minus %.2f} (syst)' % (exp_nom[0], exp_nom_stat[1], abs(exp_nom_stat[2]), exp_up_sys, exp_do_sys) + if _bin == 10: exp_fit = 'Exp. #sigma_{bin, 2e2mu, 5} = %.2f^{#plus %.2f}_{#minus %.2f} (stat)^{#plus %.2f}_{#minus %.2f} (syst)' % (exp_nom[0], exp_nom_stat[1], abs(exp_nom_stat[2]), exp_up_sys, exp_do_sys) + if _bin == 11: exp_fit = 'Exp. #sigma_{bin, 4l, 5} = %.2f^{#plus %.2f}_{#minus %.2f} (stat)^{#plus %.2f}_{#minus %.2f} (syst)' % (exp_nom[0], exp_nom_stat[1], abs(exp_nom_stat[2]), exp_up_sys, exp_do_sys) + if _bin == 12: exp_fit = 'Exp. #sigma_{bin, 2e2mu, 6} = %.2f^{#plus %.2f}_{#minus %.2f} (stat)^{#plus %.2f}_{#minus %.2f} (syst)' % (exp_nom[0], exp_nom_stat[1], abs(exp_nom_stat[2]), exp_up_sys, exp_do_sys) + if _bin == 13: exp_fit = 'Exp. #sigma_{bin, 4l, 6} = %.2f^{#plus %.2f}_{#minus %.2f} (stat)^{#plus %.2f}_{#minus %.2f} (syst)' % (exp_nom[0], exp_nom_stat[1], abs(exp_nom_stat[2]), exp_up_sys, exp_do_sys) + if _bin == 14: exp_fit = 'Exp. #sigma_{bin, 2e2mu, 7} = %.2f^{#plus %.2f}_{#minus %.2f} (stat)^{#plus %.2f}_{#minus %.2f} (syst)' % (exp_nom[0], exp_nom_stat[1], abs(exp_nom_stat[2]), exp_up_sys, exp_do_sys) + if _bin == 15: exp_fit = 'Exp. #sigma_{bin, 4l, 7} = %.2f^{#plus %.2f}_{#minus %.2f} (stat)^{#plus %.2f}_{#minus %.2f} (syst)' % (exp_nom[0], exp_nom_stat[1], abs(exp_nom_stat[2]), exp_up_sys, exp_do_sys) + if _bin == 16: exp_fit = 'Exp. #sigma_{bin, 2e2mu, 8} = %.2f^{#plus %.2f}_{#minus %.2f} (stat)^{#plus %.2f}_{#minus %.2f} (syst)' % (exp_nom[0], exp_nom_stat[1], abs(exp_nom_stat[2]), exp_up_sys, exp_do_sys) + if _bin == 17: exp_fit = 'Exp. #sigma_{bin, 4l, 8} = %.2f^{#plus %.2f}_{#minus %.2f} (stat)^{#plus %.2f}_{#minus %.2f} (syst)' % (exp_nom[0], exp_nom_stat[1], abs(exp_nom_stat[2]), exp_up_sys, exp_do_sys) + if _bin == 18: exp_fit = 'Exp. #sigma_{bin, 2e2mu, 9} = %.2f^{#plus %.2f}_{#minus %.2f} (stat)^{#plus %.2f}_{#minus %.2f} (syst)' % (exp_nom[0], exp_nom_stat[1], abs(exp_nom_stat[2]), exp_up_sys, exp_do_sys) + if _bin == 19: exp_fit = 'Exp. #sigma_{bin, 4l, 9} = %.2f^{#plus %.2f}_{#minus %.2f} (stat)^{#plus %.2f}_{#minus %.2f} (syst)' % (exp_nom[0], exp_nom_stat[1], abs(exp_nom_stat[2]), exp_up_sys, exp_do_sys) + if _bin == 20: exp_fit = 'Exp. #sigma_{bin, 2e2mu, 10} = %.2f^{#plus %.2f}_{#minus %.2f} (stat)^{#plus %.2f}_{#minus %.2f} (syst)' % (exp_nom[0], exp_nom_stat[1], abs(exp_nom_stat[2]), exp_up_sys, exp_do_sys) + if _bin == 21: exp_fit = 'Exp. #sigma_{bin, 4l, 10} = %.2f^{#plus %.2f}_{#minus %.2f} (stat)^{#plus %.2f}_{#minus %.2f} (syst)' % (exp_nom[0], exp_nom_stat[1], abs(exp_nom_stat[2]), exp_up_sys, exp_do_sys) else: exp_fit = 'Exp. #sigma_{bin, %d} = %.2f^{#plus %.2f}_{#minus %.2f} (stat)^{#plus %.2f}_{#minus %.2f} (syst)' % (_bin, exp_nom[0], exp_nom_stat[1], abs(exp_nom_stat[2]), exp_up_sys, exp_do_sys) Text3.SetTextAlign(12); @@ -587,7 +631,7 @@ def BuildScan(scan, param, files, color, yvals, ycut): if not 'jet' in obsName or doubleDiff: if ('pTj1' in obsName) and not doubleDiff: latex2.DrawLatex(0.55,0.65, str(obs_bins[_bin])+' < '+label+' < '+str(obs_bins[_bin+1])) - elif 'mass4l' in obsName: + elif obsName.startswith("mass4l"): latex2.DrawLatex(0.55,0.65, str(obs_bins[0])+' < '+label+' < '+str(obs_bins[1])) elif doubleDiff: latex2.DrawLatex(0.55,0.65, str(obs_bins[_bin][0])+' < '+label+' < '+str(obs_bins[_bin][1])) @@ -603,6 +647,18 @@ def BuildScan(scan, param, files, color, yvals, ycut): if _bin == 7: latex2.DrawLatex(0.55,0.65, str(obs_bins[3])+' < '+label+' < '+str(obs_bins[4])) if _bin == 8: latex2.DrawLatex(0.55,0.65, str(obs_bins[4])+' < '+label+' < '+str(obs_bins[5])) if _bin == 9: latex2.DrawLatex(0.55,0.65, str(obs_bins[4])+' < '+label+' < '+str(obs_bins[5])) + if _bin == 10: latex2.DrawLatex(0.55,0.65, str(obs_bins[5])+' < '+label+' < '+str(obs_bins[6])) + if _bin == 11: latex2.DrawLatex(0.55,0.65, str(obs_bins[5])+' < '+label+' < '+str(obs_bins[6])) + if _bin == 12: latex2.DrawLatex(0.55,0.65, str(obs_bins[6])+' < '+label+' < '+str(obs_bins[7])) + if _bin == 13: latex2.DrawLatex(0.55,0.65, str(obs_bins[6])+' < '+label+' < '+str(obs_bins[7])) + if _bin == 14: latex2.DrawLatex(0.55,0.65, str(obs_bins[7])+' < '+label+' < '+str(obs_bins[8])) + if _bin == 15: latex2.DrawLatex(0.55,0.65, str(obs_bins[7])+' < '+label+' < '+str(obs_bins[8])) + if _bin == 16: latex2.DrawLatex(0.55,0.65, str(obs_bins[8])+' < '+label+' < '+str(obs_bins[9])) + if _bin == 17: latex2.DrawLatex(0.55,0.65, str(obs_bins[8])+' < '+label+' < '+str(obs_bins[9])) + if _bin == 18: latex2.DrawLatex(0.55,0.65, str(obs_bins[9])+' < '+label+' < '+str(obs_bins[10])) + if _bin == 19: latex2.DrawLatex(0.55,0.65, str(obs_bins[9])+' < '+label+' < '+str(obs_bins[10])) + if _bin == 20: latex2.DrawLatex(0.55,0.65, str(obs_bins[10])+' < '+label+' < '+str(obs_bins[11])) + if _bin == 21: latex2.DrawLatex(0.55,0.65, str(obs_bins[10])+' < '+label+' < '+str(obs_bins[11])) else: latex2.DrawLatex(0.45,0.65, str(obs_bins[_bin])+' < '+label+' < '+str(obs_bins[_bin+1])) else: @@ -619,7 +675,7 @@ def BuildScan(scan, param, files, color, yvals, ycut): c.Update() if(opt.UNBLIND): - if obsName!='mass4l': + if not obsName.startswith("mass4l"): resultsXS_data['SM_125_'+obsName+'_genbin'+str(i)] = {"uncerDn": -1.0*abs(obs_nom[2]), "uncerUp": obs_nom[1], "central": obs_nom[0]} resultsXS_data['SM_125_'+obsName+'_genbin'+str(i)+'_statOnly'] = {"uncerDn": -1.0*abs(obs_nom_stat[2]), "uncerUp": obs_nom_stat[1], "central": obs_nom[0]} else: @@ -636,7 +692,7 @@ def BuildScan(scan, param, files, color, yvals, ycut): resultsXS_data_v2['SM_125_'+obsName+'_4e_genbin0'] = {"uncerDn": -1.0*abs(obs_nom[2]), "uncerUp": obs_nom[1], "central": obs_nom[0]} resultsXS_data_v2['SM_125_'+obsName+'_4e_genbin0_statOnly'] = {"uncerDn": -1.0*abs(obs_nom_stat[2]), "uncerUp": obs_nom_stat[1], "central": obs_nom[0]} - if obsName=='mass4l': + if obsName.startswith("mass4l"): if _bin==0: resultsXS_asimov['SM_125_'+obsName+'_genbin'+str(i)] = {"uncerDn": -1.0*abs(exp_nom[2]), "uncerUp": exp_nom[1], "central": exp_nom[0]} resultsXS_asimov['SM_125_'+obsName+'_genbin'+str(i)+'_statOnly'] = {"uncerDn": -1.0*abs(exp_nom_stat[2]), "uncerUp": exp_nom_stat[1], "central": exp_nom[0]} @@ -680,6 +736,36 @@ def BuildScan(scan, param, files, color, yvals, ycut): elif _bin==9: resultsXS_asimov_v4['SM_125_'+obsName+'_4l_genbin4'] = {"uncerDn": -1.0*abs(exp_nom[2]), "uncerUp": exp_nom[1], "central": exp_nom[0]} resultsXS_asimov_v4['SM_125_'+obsName+'_4l_genbin4_statOnly'] = {"uncerDn": -1.0*abs(exp_nom_stat[2]), "uncerUp": exp_nom_stat[1], "central": exp_nom[0]} + elif _bin==10: + resultsXS_asimov_v4['SM_125_'+obsName+'_2e2mu_genbin5'] = {"uncerDn": -1.0*abs(exp_nom[2]), "uncerUp": exp_nom[1], "central": exp_nom[0]} + resultsXS_asimov_v4['SM_125_'+obsName+'_2e2mu_genbin5_statOnly'] = {"uncerDn": -1.0*abs(exp_nom_stat[2]), "uncerUp": exp_nom_stat[1], "central": exp_nom[0]} + elif _bin==11: + resultsXS_asimov_v4['SM_125_'+obsName+'_4l_genbin5'] = {"uncerDn": -1.0*abs(exp_nom[2]), "uncerUp": exp_nom[1], "central": exp_nom[0]} + resultsXS_asimov_v4['SM_125_'+obsName+'_4l_genbin5_statOnly'] = {"uncerDn": -1.0*abs(exp_nom_stat[2]), "uncerUp": exp_nom_stat[1], "central": exp_nom[0]} + elif _bin==12: + resultsXS_asimov_v4['SM_125_'+obsName+'_2e2mu_genbin6'] = {"uncerDn": -1.0*abs(exp_nom[2]), "uncerUp": exp_nom[1], "central": exp_nom[0]} + resultsXS_asimov_v4['SM_125_'+obsName+'_2e2mu_genbin6_statOnly'] = {"uncerDn": -1.0*abs(exp_nom_stat[2]), "uncerUp": exp_nom_stat[1], "central": exp_nom[0]} + elif _bin==13: + resultsXS_asimov_v4['SM_125_'+obsName+'_4l_genbin6'] = {"uncerDn": -1.0*abs(exp_nom[2]), "uncerUp": exp_nom[1], "central": exp_nom[0]} + resultsXS_asimov_v4['SM_125_'+obsName+'_4l_genbin6_statOnly'] = {"uncerDn": -1.0*abs(exp_nom_stat[2]), "uncerUp": exp_nom_stat[1], "central": exp_nom[0]} + elif _bin==14: + resultsXS_asimov_v4['SM_125_'+obsName+'_2e2mu_genbin7'] = {"uncerDn": -1.0*abs(exp_nom[2]), "uncerUp": exp_nom[1], "central": exp_nom[0]} + resultsXS_asimov_v4['SM_125_'+obsName+'_2e2mu_genbin7_statOnly'] = {"uncerDn": -1.0*abs(exp_nom_stat[2]), "uncerUp": exp_nom_stat[1], "central": exp_nom[0]} + elif _bin==15: + resultsXS_asimov_v4['SM_125_'+obsName+'_4l_genbin7'] = {"uncerDn": -1.0*abs(exp_nom[2]), "uncerUp": exp_nom[1], "central": exp_nom[0]} + resultsXS_asimov_v4['SM_125_'+obsName+'_4l_genbin7_statOnly'] = {"uncerDn": -1.0*abs(exp_nom_stat[2]), "uncerUp": exp_nom_stat[1], "central": exp_nom[0]} + elif _bin==16: + resultsXS_asimov_v4['SM_125_'+obsName+'_2e2mu_genbin8'] = {"uncerDn": -1.0*abs(exp_nom[2]), "uncerUp": exp_nom[1], "central": exp_nom[0]} + resultsXS_asimov_v4['SM_125_'+obsName+'_2e2mu_genbin8_statOnly'] = {"uncerDn": -1.0*abs(exp_nom_stat[2]), "uncerUp": exp_nom_stat[1], "central": exp_nom[0]} + elif _bin==17: + resultsXS_asimov_v4['SM_125_'+obsName+'_4l_genbin8'] = {"uncerDn": -1.0*abs(exp_nom[2]), "uncerUp": exp_nom[1], "central": exp_nom[0]} + resultsXS_asimov_v4['SM_125_'+obsName+'_4l_genbin8_statOnly'] = {"uncerDn": -1.0*abs(exp_nom_stat[2]), "uncerUp": exp_nom_stat[1], "central": exp_nom[0]} + elif _bin==18: + resultsXS_asimov_v4['SM_125_'+obsName+'_2e2mu_genbin9'] = {"uncerDn": -1.0*abs(exp_nom[2]), "uncerUp": exp_nom[1], "central": exp_nom[0]} + resultsXS_asimov_v4['SM_125_'+obsName+'_2e2mu_genbin5_statOnly'] = {"uncerDn": -1.0*abs(exp_nom_stat[2]), "uncerUp": exp_nom_stat[1], "central": exp_nom[0]} + elif _bin==19: + resultsXS_asimov_v4['SM_125_'+obsName+'_4l_genbin9'] = {"uncerDn": -1.0*abs(exp_nom[2]), "uncerUp": exp_nom[1], "central": exp_nom[0]} + resultsXS_asimov_v4['SM_125_'+obsName+'_4l_genbin5_statOnly'] = {"uncerDn": -1.0*abs(exp_nom_stat[2]), "uncerUp": exp_nom_stat[1], "central": exp_nom[0]} else: resultsXS_asimov['SM_125_'+obsName+'_genbin'+str(i)] = {"uncerDn": -1.0*abs(exp_nom[2]), "uncerUp": exp_nom[1], "central": exp_nom[0]} resultsXS_asimov['SM_125_'+obsName+'_genbin'+str(i)+'_statOnly'] = {"uncerDn": -1.0*abs(exp_nom_stat[2]), "uncerUp": exp_nom_stat[1], "central": exp_nom[0]} @@ -694,14 +780,14 @@ def BuildScan(scan, param, files, color, yvals, ycut): else: with open('resultsXS_LHScan_expected_'+obsName+'_v3.py', 'w') as f: f.write('resultsXS = '+str(resultsXS_asimov)+' \n') - if obsName=='mass4l': + if obsName.startswith("mass4l"): with open('resultsXS_LHScan_expected_'+obsName+'_v2.py', 'w') as f: f.write('resultsXS = '+str(resultsXS_asimov_v2)+' \n') if(opt.UNBLIND): with open('resultsXS_LHScan_observed_'+obsName+'_v3.py', 'w') as f: f.write('resultsXS = '+str(resultsXS_data)+' \n') - if obsName=='mass4l': + if obsName.startswith("mass4l"): with open('resultsXS_LHScan_observed_'+obsName+'_v2.py', 'w') as f: f.write('resultsXS = '+str(resultsXS_data_v2)+' \n') # raw_input() diff --git a/coefficients/JES/PrintJES.py b/coefficients/JES/PrintJES.py index 90c9d36..108d9bf 100644 --- a/coefficients/JES/PrintJES.py +++ b/coefficients/JES/PrintJES.py @@ -8,7 +8,6 @@ print 'Welcome in RunJES!' -jesNames = ['Total', 'Abs', 'Abs_year', 'BBEC1', 'BBEC1_year', 'EC2', 'EC2_year', 'FlavQCD', 'HF', 'HF_year', 'RelBal', 'RelSample_year'] def parseOptions(): @@ -26,9 +25,9 @@ def parseOptions(): global opt, args (opt, args) = parser.parse_args() - if (opt.OBSBINS=='' and opt.OBSNAME!='inclusive'): - parser.error('Bin boundaries not specified for differential measurement. Exiting...') - sys.exit() + # if (opt.OBSBINS=='' and opt.OBSNAME!='inclusive'): + # parser.error('Bin boundaries not specified for differential measurement. Exiting...') + # sys.exit() # parse the arguments and options @@ -48,12 +47,15 @@ def parseOptions(): year = opt.YEAR +jesNames = ['Total', 'Abs', 'Abs_year', 'BBEC1', 'BBEC1_year', 'EC2', 'EC2_year', 'FlavQCD', 'HF', 'HF_year', 'RelBal', 'RelSample_year'] + print (obsname, year, obsname_out) -obs_bins, doubleDiff = binning(opt.OBSBINS) +obs_bins, doubleDiff = binning(opt.OBSNAME) -_temp = __import__('JESNP_evts_'+obsname_out+'_'+str(year), globals(), locals(), ['evts']) +_temp = __import__('JESNP_evts_'+obsname_out, globals(), locals(), ['evts','evts_noWeight']) evts = _temp.evts -_temp = __import__('JESNP_'+obsname_out+'_'+str(year), globals(), locals(), ['JESNP']) +evts_noWeight = _temp.evts_noWeight +_temp = __import__('JESNP_'+obsname_out, globals(), locals(), ['JESNP']) JESNP = _temp.JESNP # Check if the folder for tables exist @@ -62,72 +64,67 @@ def parseOptions(): # Tables with numerical values tables = {} +inclusiveJES = {} for fState in ['2e2mu', '4e', '4mu']: - for jesName in jesNames: + for recobin in range(len(obs_bins)-1): table = [] - for recobin in range(len(obs_bins)-1): - nominal_incl = 0 - up_incl = 0 - dn_incl = 0 - for genbin in range(len(obs_bins)-1): - nominal_incl += evts['fiducial_'+jesName+'_'+fState+'_'+obsname_out+'_genbin'+str(genbin)+'_recobin'+str(recobin)] - up_incl += evts['fiducial_jesup_'+jesName+'_'+fState+'_'+obsname_out+'_genbin'+str(genbin)+'_recobin'+str(recobin)] - dn_incl += evts['fiducial_jesdn_'+jesName+'_'+fState+'_'+obsname_out+'_genbin'+str(genbin)+'_recobin'+str(recobin)] - table.append(['fiducial_'+jesName+'_'+fState+'_'+obsname_out+'_genbin'+str(genbin)+'_recobin'+str(recobin), - evts['fiducial_'+jesName+'_'+fState+'_'+obsname_out+'_genbin'+str(genbin)+'_recobin'+str(recobin)], - evts['fiducial_jesup_'+jesName+'_'+fState+'_'+obsname_out+'_genbin'+str(genbin)+'_recobin'+str(recobin)], - evts['fiducial_jesdn_'+jesName+'_'+fState+'_'+obsname_out+'_genbin'+str(genbin)+'_recobin'+str(recobin)], - JESNP['fiducial_'+jesName+'_'+fState+'_'+obsname_out+'_genbin'+str(genbin)+'_recobin'+str(recobin)]]) - - nominal_incl += evts['nonFiducial_'+jesName+'_'+fState+'_'+obsname_out+'_genbin'+str(recobin)+'_recobin'+str(recobin)] - up_incl += evts['nonFiducial_jesup_'+jesName+'_'+fState+'_'+obsname_out+'_genbin'+str(recobin)+'_recobin'+str(recobin)] - dn_incl += evts['nonFiducial_jesdn_'+jesName+'_'+fState+'_'+obsname_out+'_genbin'+str(recobin)+'_recobin'+str(recobin)] - table.append(['nonFiducial_'+jesName+'_'+fState+'_'+obsname_out+'_genbin'+str(recobin)+'_recobin'+str(recobin), - evts['nonFiducial_'+jesName+'_'+fState+'_'+obsname_out+'_genbin'+str(recobin)+'_recobin'+str(recobin)], - evts['nonFiducial_jesup_'+jesName+'_'+fState+'_'+obsname_out+'_genbin'+str(recobin)+'_recobin'+str(recobin)], - evts['nonFiducial_jesdn_'+jesName+'_'+fState+'_'+obsname_out+'_genbin'+str(recobin)+'_recobin'+str(recobin)], - JESNP['nonFiducial_'+jesName+'_'+fState+'_'+obsname_out+'_genbin'+str(recobin)+'_recobin'+str(recobin)]]) - - nominal_incl += evts['nonResonant_'+jesName+'_'+fState+'_'+obsname_out+'_genbin'+str(recobin)+'_recobin'+str(recobin)] - up_incl += evts['nonResonant_jesup_'+jesName+'_'+fState+'_'+obsname_out+'_genbin'+str(recobin)+'_recobin'+str(recobin)] - dn_incl += evts['nonResonant_jesdn_'+jesName+'_'+fState+'_'+obsname_out+'_genbin'+str(recobin)+'_recobin'+str(recobin)] - table.append(['nonResonant_'+jesName+'_'+fState+'_'+obsname_out+'_genbin'+str(recobin)+'_recobin'+str(recobin), - evts['nonResonant_'+jesName+'_'+fState+'_'+obsname_out+'_genbin'+str(recobin)+'_recobin'+str(recobin)], - evts['nonResonant_jesup_'+jesName+'_'+fState+'_'+obsname_out+'_genbin'+str(recobin)+'_recobin'+str(recobin)], - evts['nonResonant_jesdn_'+jesName+'_'+fState+'_'+obsname_out+'_genbin'+str(recobin)+'_recobin'+str(recobin)], - JESNP['nonResonant_'+jesName+'_'+fState+'_'+obsname_out+'_genbin'+str(recobin)+'_recobin'+str(recobin)]]) - table.append(['fid_nonFid_nonRes_INCLUSIVE', nominal_incl, up_incl, dn_incl, str(round(dn_incl/nominal_incl,3))+'/'+str(round(up_incl/nominal_incl,3))]) - - nominal_incl += evts['qqzz_'+jesName+'_'+fState+'_'+obsname_out+'_genbin'+str(recobin)+'_recobin'+str(recobin)] - up_incl += evts['qqzz_jesup_'+jesName+'_'+fState+'_'+obsname_out+'_genbin'+str(recobin)+'_recobin'+str(recobin)] - dn_incl += evts['qqzz_jesdn_'+jesName+'_'+fState+'_'+obsname_out+'_genbin'+str(recobin)+'_recobin'+str(recobin)] - table.append(['qqzz_'+jesName+'_'+fState+'_'+obsname_out+'_genbin'+str(recobin)+'_recobin'+str(recobin), - evts['qqzz_'+jesName+'_'+fState+'_'+obsname_out+'_genbin'+str(recobin)+'_recobin'+str(recobin)], - evts['qqzz_jesup_'+jesName+'_'+fState+'_'+obsname_out+'_genbin'+str(recobin)+'_recobin'+str(recobin)], - evts['qqzz_jesdn_'+jesName+'_'+fState+'_'+obsname_out+'_genbin'+str(recobin)+'_recobin'+str(recobin)], - JESNP['qqzz_'+jesName+'_'+fState+'_'+obsname_out+'_genbin'+str(recobin)+'_recobin'+str(recobin)]]) - - nominal_incl += evts['ggzz_'+jesName+'_'+fState+'_'+obsname_out+'_genbin'+str(recobin)+'_recobin'+str(recobin)] - up_incl += evts['ggzz_jesup_'+jesName+'_'+fState+'_'+obsname_out+'_genbin'+str(recobin)+'_recobin'+str(recobin)] - dn_incl += evts['ggzz_jesdn_'+jesName+'_'+fState+'_'+obsname_out+'_genbin'+str(recobin)+'_recobin'+str(recobin)] - table.append(['ggzz_'+jesName+'_'+fState+'_'+obsname_out+'_genbin'+str(recobin)+'_recobin'+str(recobin), - evts['ggzz_'+jesName+'_'+fState+'_'+obsname_out+'_genbin'+str(recobin)+'_recobin'+str(recobin)], - evts['ggzz_jesup_'+jesName+'_'+fState+'_'+obsname_out+'_genbin'+str(recobin)+'_recobin'+str(recobin)], - evts['ggzz_jesdn_'+jesName+'_'+fState+'_'+obsname_out+'_genbin'+str(recobin)+'_recobin'+str(recobin)], - JESNP['ggzz_'+jesName+'_'+fState+'_'+obsname_out+'_genbin'+str(recobin)+'_recobin'+str(recobin)]]) - - nominal_incl += evts['ZX_'+fState+'_'+obsname_out+'_genbin'+str(recobin)+'_recobin'+str(recobin)] - up_incl += evts['ZX_jesup_'+fState+'_'+obsname_out+'_genbin'+str(recobin)+'_recobin'+str(recobin)] - dn_incl += evts['ZX_jesdn_'+fState+'_'+obsname_out+'_genbin'+str(recobin)+'_recobin'+str(recobin)] - table.append(['ZX_'+fState+'_'+obsname_out+'_genbin'+str(recobin)+'_recobin'+str(recobin), - evts['ZX_'+fState+'_'+obsname_out+'_genbin'+str(recobin)+'_recobin'+str(recobin)], - evts['ZX_jesup_'+fState+'_'+obsname_out+'_genbin'+str(recobin)+'_recobin'+str(recobin)], - evts['ZX_jesdn_'+fState+'_'+obsname_out+'_genbin'+str(recobin)+'_recobin'+str(recobin)], - JESNP['ZX_'+fState+'_'+obsname_out+'_genbin'+str(recobin)+'_recobin'+str(recobin)]]) - table.append(['INCLUSIVE', nominal_incl, up_incl, dn_incl, str(round(dn_incl/nominal_incl,3))+'/'+str(round(up_incl/nominal_incl,3))]) + for jesName in jesNames: + # nominal_incl = 0 + # up_incl = 0 + # dn_incl = 0 + # nominal_incl += evts['signal_'+jesName+'_'+year+'_'+fState+'_'+obsname_out+'_recobin'+str(recobin)] + # up_incl += evts['signal_jesup_'+jesName+'_'+year+'_'+fState+'_'+obsname_out+'_recobin'+str(recobin)] + # dn_incl += evts['signal_jesdn_'+jesName+'_'+year+'_'+fState+'_'+obsname_out+'_recobin'+str(recobin)] + table.append(['signal_'+jesName+'_'+fState+'_'+str(year)+'_'+obsname_out+'_recobin'+str(recobin), + evts_noWeight['signal_'+jesName+'_'+fState+'_'+str(year)+'_'+obsname_out+'_recobin'+str(recobin)], + evts_noWeight['signal_jesup_'+jesName+'_'+fState+'_'+str(year)+'_'+obsname_out+'_recobin'+str(recobin)], + evts_noWeight['signal_jesdn_'+jesName+'_'+fState+'_'+str(year)+'_'+obsname_out+'_recobin'+str(recobin)], + evts['signal_'+jesName+'_'+fState+'_'+str(year)+'_'+obsname_out+'_recobin'+str(recobin)], + evts['signal_jesup_'+jesName+'_'+fState+'_'+str(year)+'_'+obsname_out+'_recobin'+str(recobin)], + evts['signal_jesdn_'+jesName+'_'+fState+'_'+str(year)+'_'+obsname_out+'_recobin'+str(recobin)], + JESNP['signal_'+jesName+'_'+fState+'_'+str(year)+'_'+obsname_out+'_recobin'+str(recobin)]]) + + # nominal_incl += evts['qqzz_'+jesName+'_'+year+'_'+fState+'_'+obsname_out+'_recobin'+str(recobin)] + # up_incl += evts['qqzz_jesup_'+jesName+'_'+year+'_'+fState+'_'+obsname_out+'_recobin'+str(recobin)] + # dn_incl += evts['qqzz_jesdn_'+jesName+'_'+year+'_'+fState+'_'+obsname_out+'_recobin'+str(recobin)] + table.append(['qqzz_'+jesName+'_'+fState+'_'+str(year)+'_'+obsname_out+'_recobin'+str(recobin), + evts_noWeight['qqzz_'+jesName+'_'+fState+'_'+str(year)+'_'+obsname_out+'_recobin'+str(recobin)], + evts_noWeight['qqzz_jesup_'+jesName+'_'+fState+'_'+str(year)+'_'+obsname_out+'_recobin'+str(recobin)], + evts_noWeight['qqzz_jesdn_'+jesName+'_'+fState+'_'+str(year)+'_'+obsname_out+'_recobin'+str(recobin)], + evts['qqzz_'+jesName+'_'+fState+'_'+str(year)+'_'+obsname_out+'_recobin'+str(recobin)], + evts['qqzz_jesup_'+jesName+'_'+fState+'_'+str(year)+'_'+obsname_out+'_recobin'+str(recobin)], + evts['qqzz_jesdn_'+jesName+'_'+fState+'_'+str(year)+'_'+obsname_out+'_recobin'+str(recobin)], + JESNP['qqzz_'+jesName+'_'+fState+'_'+str(year)+'_'+obsname_out+'_recobin'+str(recobin)]]) + + # nominal_incl += evts['ggzz_'+jesName+'_'+year+'_'+fState+'_'+obsname_out+'_recobin'+str(recobin)] + # up_incl += evts['ggzz_jesup_'+jesName+'_'+year+'_'+fState+'_'+obsname_out+'_recobin'+str(recobin)] + # dn_incl += evts['ggzz_jesdn_'+jesName+'_'+year+'_'+fState+'_'+obsname_out+'_recobin'+str(recobin)] + table.append(['ggzz_'+jesName+'_'+fState+'_'+str(year)+'_'+obsname_out+'_recobin'+str(recobin), + evts_noWeight['ggzz_'+jesName+'_'+fState+'_'+str(year)+'_'+obsname_out+'_recobin'+str(recobin)], + evts_noWeight['ggzz_jesup_'+jesName+'_'+fState+'_'+str(year)+'_'+obsname_out+'_recobin'+str(recobin)], + evts_noWeight['ggzz_jesdn_'+jesName+'_'+fState+'_'+str(year)+'_'+obsname_out+'_recobin'+str(recobin)], + evts['ggzz_'+jesName+'_'+fState+'_'+str(year)+'_'+obsname_out+'_recobin'+str(recobin)], + evts['ggzz_jesup_'+jesName+'_'+fState+'_'+str(year)+'_'+obsname_out+'_recobin'+str(recobin)], + evts['ggzz_jesdn_'+jesName+'_'+fState+'_'+str(year)+'_'+obsname_out+'_recobin'+str(recobin)], + JESNP['ggzz_'+jesName+'_'+fState+'_'+str(year)+'_'+obsname_out+'_recobin'+str(recobin)]]) + + # nominal_incl += evts['ZX_'+fState+'_'+obsname_out+'_recobin'+str(recobin)] + # up_incl += evts['ZX_jesup_'+fState+'_'+obsname_out+'_recobin'+str(recobin)] + # dn_incl += evts['ZX_jesdn_'+fState+'_'+obsname_out+'_recobin'+str(recobin)] + table.append(['ZX_'+fState+'_'+str(year)+'_'+obsname_out+'_recobin'+str(recobin), + evts_noWeight['ZX_'+fState+'_'+str(year)+'_'+obsname_out+'_recobin'+str(recobin)], + evts_noWeight['ZX_jesup_'+fState+'_'+str(year)+'_'+obsname_out+'_recobin'+str(recobin)], + evts_noWeight['ZX_jesdn_'+fState+'_'+str(year)+'_'+obsname_out+'_recobin'+str(recobin)], + evts['ZX_'+fState+'_'+str(year)+'_'+obsname_out+'_recobin'+str(recobin)], + evts['ZX_jesup_'+fState+'_'+str(year)+'_'+obsname_out+'_recobin'+str(recobin)], + evts['ZX_jesdn_'+fState+'_'+str(year)+'_'+obsname_out+'_recobin'+str(recobin)], + JESNP['ZX_'+fState+'_'+str(year)+'_'+obsname_out+'_recobin'+str(recobin)]]) + + # table.append(['INCLUSIVE', nominal_incl, up_incl, dn_incl, str(round(dn_incl/nominal_incl,3))+'/'+str(round(up_incl/nominal_incl,3))]) table.append([]) - tables[jesName,fState] = tabulate(table, headers=['bin', 'nominal', 'jes_up', 'jes_dn', 'ratio(dn/up)'], numalign="right", tablefmt="github") + tables[fState, recobin] = tabulate(table, headers=['bin', 'nominal_evts', 'jes_up_evts', 'jes_dn_evts', 'nominal', 'jes_up', 'jes_dn', 'ratio(dn/up)'], numalign="right", tablefmt="github") - with open('tables/JESNP_table_'+obsname_out+'_'+str(year)+'_'+jesName+'_'+fState+'.py', 'w') as f: - f.write(tables[jesName,fState]) + with open('tables/'+obsname_out+'/JESNP_table_'+obsname_out+'_'+fState+'_'+str(year)+'_recobin'+str(recobin)+'.py', 'w') as f: + f.write(tables[fState,recobin]) +>>>>>>> abacad9bead1eba9b11795c1ae0fc95f872d30a7 diff --git a/coefficients/JES/RunJES.py b/coefficients/JES/RunJES.py index 53da0b3..84d18ca 100644 --- a/coefficients/JES/RunJES.py +++ b/coefficients/JES/RunJES.py @@ -2,9 +2,9 @@ import os import pandas as pd import matplotlib as mpl -if os.environ.get('DISPLAY','') == '': - print('no display found. Using non-interactive Agg backend') - mpl.use('Agg') +# if os.environ.get('DISPLAY','') == '': +# print('no display found. Using non-interactive Agg backend') +# mpl.use('Agg') import matplotlib.pyplot as plt from matplotlib.lines import Line2D import matplotlib.ticker as ticker @@ -41,9 +41,9 @@ def parseOptions(): global opt, args (opt, args) = parser.parse_args() - if (opt.OBSBINS=='' and opt.OBSNAME!='inclusive'): - parser.error('Bin boundaries not specified for differential measurement. Exiting...') - sys.exit() + # if (opt.OBSBINS=='' and opt.OBSNAME!='inclusive'): + # parser.error('Bin boundaries not specified for differential measurement. Exiting...') + # sys.exit() # parse the arguments and options @@ -51,137 +51,32 @@ def parseOptions(): parseOptions() -# # ------------------------------- FUNCTIONS TO CALCULATE JES BOTH IN 1D AND 2D CASE ------------------------------- -# # -------------- 1D -------------- -# def computeJES(obsname, obs_bins, year, fState, m4l_low, m4l_high): -# -# if fState != '4l': -# sel = (d_sig[year].ZZMass >= int(m4l_low)) & (d_sig[year].ZZMass <= int(m4l_high)) & (d_sig[year].FinState_reco == fState) -# else: -# sel = (d_sig[year].ZZMass >= int(m4l_low)) & (d_sig[year].ZZMass <= int(m4l_high)) -# -# for i in jesNames: -# fig = plt.figure(figsize=(6,5)) -# # Upper frame -# frame1 = fig.add_axes((.1, .35, .8, .6)) -# plt.title('CMS', weight = 'bold', loc = 'left', fontsize = 15) -# plt.title(fState, loc = 'right', fontsize = 14) -# n, bins, _= plt.hist([d_sig[year][sel][obsname],d_sig[year][sel][obsname+'_jesup_'+i],d_sig[year][sel][obsname+'_jesdn_'+i]], -# bins = obs_bins, -# weights = [d_sig[year][sel]['weight_reco'],d_sig[year][sel]['weight_reco'],d_sig[year][sel]['weight_reco']], -# histtype='step', -# color = ['blue', 'orange', 'green'], -# label = ['nominal', 'jesup_'+i, 'jesdn_'+i]) -# if obsname == 'pTj1': plt.xlim(0,250) -# ratio_up = n[1]/n[0] -# ratio_dn = n[2]/n[0] -# # Fill JES dictionary -# for b in range(len(bins)-1): -# if abs(ratio_dn[b] - ratio_up[b]) < 0.001: # If they are equal, only one value in datacards -# jesNP[year,fState,'recobin_'+str(b),i] = '%.3f' %(ratio_dn[b]) -# else: -# jesNP[year,fState,'recobin_'+str(b),i] = '%.3f/%.3f' %(ratio_dn[b], ratio_up[b]) -# plt.legend() -# frame1.set_xticklabels([]) #Remove x-tic labels for the first frame -# # Lower (ratio) frame -# frame2=fig.add_axes((.1,.1,.8,.2)) -# for index in range(len(bins)-1): -# plt.hlines(ratio_up[index], bins[index], bins[index+1], 'orange') -# plt.hlines(ratio_dn[index], bins[index], bins[index+1], 'green') -# plt.axhline(1,color='blue',ls='--') -# if obsname == 'pTj1': plt.xlim(0,250) -# plt.savefig('plots/'+obs_reco+'/jesNP_'+str(year)+'_'+fState+'_'+i+'.png',dpi=400, bbox_inches='tight') -# # plt.show() -# plt.show() -# plt.close(fig) -# -# # -------------- 2D -------------- -# def computeJES_2D(obsname, obsname_2nd, obs_bins, year, fState, m4l_low, m4l_high): -# -# if fState != '4l': -# sel = (d_sig[year].ZZMass >= int(m4l_low)) & (d_sig[year].ZZMass <= int(m4l_high)) & (d_sig[year].FinState_reco == fState) -# else: -# sel = (d_sig[year].ZZMass >= int(m4l_low)) & (d_sig[year].ZZMass <= int(m4l_high)) -# -# for i in jesNames: -# fig = plt.figure(figsize=(6,5)) -# # Upper frame -# frame1 = fig.add_axes((.1, .35, .8, .6)) -# plt.title('CMS', weight = 'bold', loc = 'left', fontsize = 15) -# plt.title(fState, loc = 'right', fontsize = 14) -# for index in obs_bins: -# sel_nominal = sel & (d_sig[year][obsname] >= obs_bins[index][0]) & (d_sig[year][obsname] < obs_bins[index][1]) & (d_sig[year][obsname_2nd] >= obs_bins[index][2]) & (d_sig[year][obsname_2nd] < obs_bins[index][3]) -# plt.hlines(d_sig[year][sel_nominal]['weight_reco'].sum(), index, index+1, 'blue', label='nominal') -# -# sel_up = sel & (d_sig[year][obsname+'_jesup_'+i] >= obs_bins[index][0]) & (d_sig[year][obsname+'_jesup_'+i] < obs_bins[index][1]) & (d_sig[year][obsname_2nd+'_jesup_'+i] >= obs_bins[index][2]) & (d_sig[year][obsname_2nd+'_jesup_'+i] < obs_bins[index][3]) -# plt.hlines(d_sig[year][sel_up]['weight_reco'].sum(), index, index+1, 'orange', label='jesup_'+i) -# -# sel_dn = sel & (d_sig[year][obsname+'_jesdn_'+i] >= obs_bins[index][0]) & (d_sig[year][obsname+'_jesdn_'+i] < obs_bins[index][1]) & (d_sig[year][obsname_2nd+'_jesdn_'+i] >= obs_bins[index][2]) & (d_sig[year][obsname_2nd+'_jesdn_'+i] < obs_bins[index][3]) -# plt.hlines(d_sig[year][sel_dn]['weight_reco'].sum(), index, index+1, 'green', label='jesdn_'+i) -# -# # We have to set the legend entries manually -# legend_elements = [Line2D([0], [0], color='blue', label='nominal'), -# Line2D([0], [0], color='orange', label='jesup_'+i), -# Line2D([0], [0], color='green', label='jesdown_'+i)] -# plt.legend(handles=legend_elements) -# plt.gca().get_xaxis().set_major_locator(ticker.MultipleLocator(1)) -# plt.xlim(0,len(obs_bins)) -# frame1.set_xticklabels([]) -# # Lower (ratio) frame -# frame2=fig.add_axes((.1,.1,.8,.2)) -# plt.axhline(1,color='blue',ls='--') -# ratio_up = [] -# ratio_dn = [] -# for index in obs_bins: -# sel_nominal = sel & (d_sig[year][obsname] >= obs_bins[index][0]) & (d_sig[year][obsname] < obs_bins[index][1]) & (d_sig[year][obsname_2nd] >= obs_bins[index][2]) & (d_sig[year][obsname_2nd] < obs_bins[index][3]) -# -# sel_up = sel & (d_sig[year][obsname+'_jesup_'+i] >= obs_bins[index][0]) & (d_sig[year][obsname+'_jesup_'+i] < obs_bins[index][1]) & (d_sig[year][obsname_2nd+'_jesup_'+i] >= obs_bins[index][2]) & (d_sig[year][obsname_2nd+'_jesup_'+i] < obs_bins[index][3]) -# plt.hlines(d_sig[year][sel_up]['weight_reco'].sum()/d_sig[year][sel_nominal]['weight_reco'].sum(), index, index+1, 'orange', label='jesup_'+i) -# ratio_up.append(d_sig[year][sel_up]['weight_reco'].sum()/d_sig[year][sel_nominal]['weight_reco'].sum()) -# -# sel_dn = sel & (d_sig[year][obsname+'_jesdn_'+i] >= obs_bins[index][0]) & (d_sig[year][obsname+'_jesdn_'+i] < obs_bins[index][1]) & (d_sig[year][obsname_2nd+'_jesdn_'+i] >= obs_bins[index][2]) & (d_sig[year][obsname_2nd+'_jesdn_'+i] < obs_bins[index][3]) -# ratio_dn.append(d_sig[year][sel_dn]['weight_reco'].sum()/d_sig[year][sel_nominal]['weight_reco'].sum()) -# plt.hlines(d_sig[year][sel_dn]['weight_reco'].sum()/d_sig[year][sel_nominal]['weight_reco'].sum(), index, index+1, 'green', label='jesdn_'+i) -# -# plt.xlim(0,len(obs_bins)) -# xticks = [n+0.5 for n in range(len(obs_bins))] -# xticks_label = ['Bin'+str(n+1) for n in range(len(obs_bins))] -# plt.xticks(xticks, xticks_label) -# plt.savefig('plots/'+obsname+'_'+obsname_2nd+'/jesNP_'+str(year)+'_'+fState+'_'+i+'.png',dpi=400, bbox_inches='tight') -# plt.show() -# -# for b in range(len(obs_bins)): -# if abs(ratio_dn[b] - ratio_up[b]) < 0.001: # If they are equal, only one value in datacards -# jesNP[year,fState,'recobin_'+str(b),i] = '%.3f' %(ratio_dn[b]) -# else: -# jesNP[year,fState,'recobin_'+str(b),i] = '%.3f/%.3f' %(ratio_dn[b], ratio_up[b]) +def computeRatio(nominal, upVar, dnVar): + if nominal == 0: + return '-' + else: + dn_ratio = round(dnVar/nominal,3) + up_ratio = round(upVar/nominal,3) + if up_ratio==dn_ratio and up_ratio==1.000: + return '-' + elif up_ratio == dn_ratio: + return str(dn_ratio) + else: + return str(dn_ratio)+'/'+str(up_ratio) # ------------------------------- FUNCTIONS TO CALCULATE JES BOTH IN 1D AND 2D CASE ------------------------------- -def getJes(channel, m4l_low, m4l_high, obs_reco, obs_gen, obs_bins, recobin, genbin, obs_name, year, obs_reco_2nd = 'None', obs_gen_2nd = 'None', obs_name_2nd = 'None'): +def getJes(channel, m4l_low, m4l_high, obs_reco, obs_gen, obs_bins, recobin, obs_name, year, obs_reco_2nd = 'None', obs_gen_2nd = 'None', obs_name_2nd = 'None'): if not doubleDiff: #RecoBin limits I'm considering obs_reco_low = obs_bins[recobin] obs_reco_high = obs_bins[recobin+1] - #GenBin limits I'm considering - obs_gen_low = obs_bins[genbin] - obs_gen_high = obs_bins[genbin+1] - #Extrimities of gen area - obs_gen_lowest = obs_bins[0] - obs_gen_highest = obs_bins[len(obs_bins)-1] elif doubleDiff: + #First variable obs_reco_low = obs_bins[recobin][0] obs_reco_high = obs_bins[recobin][1] - obs_gen_low = obs_bins[genbin][0] - obs_gen_high = obs_bins[genbin][1] - obs_gen_lowest = min(x[0] for x in obs_bins.values()) - obs_gen_highest = max(x[1] for x in obs_bins.values()) #Second variable obs_reco_2nd_low = obs_bins[recobin][2] obs_reco_2nd_high = obs_bins[recobin][3] - obs_gen_2nd_low = obs_bins[genbin][2] - obs_gen_2nd_high = obs_bins[genbin][3] - obs_gen_2nd_lowest = min(x[2] for x in obs_bins.values()) - obs_gen_2nd_highest = max(x[3] for x in obs_bins.values()) datafr = d_sig[year] datafr_qqzz = d_bkg[year]['qqzz'] @@ -190,201 +85,92 @@ def getJes(channel, m4l_low, m4l_high, obs_reco, obs_gen, obs_bins, recobin, gen # ------------- ZX computation (at this stage it is done only the inclusive JES) ------------- if doubleDiff: - processBin = '_'+channel+'_'+obs_reco+'_'+obs_reco_2nd+'_genbin'+str(genbin)+'_recobin'+str(recobin) + processBin = '_'+channel+'_'+str(year)+'_'+obs_reco+'_'+obs_reco_2nd+'_recobin'+str(recobin) else: - processBin = '_'+channel+'_'+obs_reco+'_genbin'+str(genbin)+'_recobin'+str(recobin) + processBin = '_'+channel+'_'+str(year)+'_'+obs_reco+'_recobin'+str(recobin) - cutobs_reco_zx = (abs(datafr_zx[obs_reco]) >= obs_reco_low) & (abs(datafr_zx[obs_reco]) < obs_reco_high) - cutobs_reco_jesup_zx = (abs(datafr_zx[obs_reco+'_jesup']) >= obs_reco_low) & (abs(datafr_zx[obs_reco+'_jesup']) < obs_reco_high) - cutobs_reco_jesdn_zx = (abs(datafr_zx[obs_reco+'_jesdn']) >= obs_reco_low) & (abs(datafr_zx[obs_reco+'_jesdn']) < obs_reco_high) + cutobs_reco_zx = (datafr_zx[obs_reco] >= obs_reco_low) & (datafr_zx[obs_reco] < obs_reco_high) + cutobs_reco_jesup_zx = (datafr_zx[obs_reco+'_jesup'] >= obs_reco_low) & (datafr_zx[obs_reco+'_jesup'] < obs_reco_high) + cutobs_reco_jesdn_zx = (datafr_zx[obs_reco+'_jesdn'] >= obs_reco_low) & (datafr_zx[obs_reco+'_jesdn'] < obs_reco_high) cutchan_reco_zx = (datafr_zx['FinState_reco'] == channel) - if channel != '4l': - cutm4l_reco_zx = (datafr_zx['ZZMass'] > m4l_low) & (datafr_zx['ZZMass'] < m4l_high) & (datafr_zx['FinState_reco'] == channel) - else: - cutm4l_reco_zx = (datafr_zx['ZZMass'] > m4l_low) & (datafr_zx['ZZMass'] < m4l_high) + cutm4l_reco_zx = (datafr_zx['ZZMass'] > m4l_low) & (datafr_zx['ZZMass'] < m4l_high) & (datafr_zx['FinState_reco'] == channel) if doubleDiff: - cutobs_reco_zx &= (abs(datafr_zx[obs_reco_2nd]) >= obs_reco_2nd_low) & (abs(datafr_zx[obs_reco_2nd]) < obs_reco_2nd_high) - cutobs_reco_jesup_zx &= (abs(datafr_zx[obs_reco_2nd+'_jesup']) >= obs_reco_2nd_low) & (abs(datafr_zx[obs_reco_2nd+'_jesup']) < obs_reco_2nd_high) - cutobs_reco_jesdn_zx &= (abs(datafr_zx[obs_reco_2nd+'_jesdn']) >= obs_reco_2nd_low) & (abs(datafr_zx[obs_reco_2nd+'_jesdn']) < obs_reco_2nd_high) + cutobs_reco_zx &= (datafr_zx[obs_reco_2nd] >= obs_reco_2nd_low) & (datafr_zx[obs_reco_2nd] < obs_reco_2nd_high) + cutobs_reco_jesup_zx &= (datafr_zx[obs_reco_2nd+'_jesup'] >= obs_reco_2nd_low) & (datafr_zx[obs_reco_2nd+'_jesup'] < obs_reco_2nd_high) + cutobs_reco_jesdn_zx &= (datafr_zx[obs_reco_2nd+'_jesdn'] >= obs_reco_2nd_low) & (datafr_zx[obs_reco_2nd+'_jesdn'] < obs_reco_2nd_high) evts['ZX'+processBin] = datafr_zx[cutm4l_reco_zx & cutobs_reco_zx & cutchan_reco_zx]['yield_SR'].sum() evts['ZX_jesup'+processBin] = datafr_zx[cutm4l_reco_zx & cutobs_reco_jesup_zx & cutchan_reco_zx]['yield_SR'].sum() evts['ZX_jesdn'+processBin] = datafr_zx[cutm4l_reco_zx & cutobs_reco_jesdn_zx & cutchan_reco_zx]['yield_SR'].sum() + evts_noWeight['ZX'+processBin] = len(datafr_zx[cutm4l_reco_zx & cutobs_reco_zx & cutchan_reco_zx]) + evts_noWeight['ZX_jesup'+processBin] = len(datafr_zx[cutm4l_reco_zx & cutobs_reco_jesup_zx & cutchan_reco_zx]) + evts_noWeight['ZX_jesdn'+processBin] = len(datafr_zx[cutm4l_reco_zx & cutobs_reco_jesdn_zx & cutchan_reco_zx]) - if evts['ZX'+processBin] == 0: - ratio['ZX'+processBin] = '-' - else: - dn_ratio = round(evts['ZX_jesdn'+processBin]/evts['ZX'+processBin],3) - # if dn_ratio == 1.000: dn_ratio = '-' - up_ratio = round(evts['ZX_jesup'+processBin]/evts['ZX'+processBin],3) - # if up_ratio == 1.000: up_ratio = '-' - ratio['ZX'+processBin] = str(dn_ratio)+'/'+str(up_ratio) - - if up_ratio==dn_ratio and up_ratio==1.000: ratio['ZX'+processBin] = '-' - elif up_ratio == dn_ratio: ratio['ZX'+processBin] = str(dn_ratio) - else: ratio['ZX'+processBin] = str(dn_ratio)+'/'+str(up_ratio) + ratio['ZX'+processBin] = computeRatio(evts['ZX'+processBin], evts['ZX_jesup'+processBin], evts['ZX_jesdn'+processBin]) # ------------- signal, qqZZ, and ggZZ computation ------------- for i in jesNames: if doubleDiff: - processBin = '_'+i+'_'+channel+'_'+obs_reco+'_'+obs_reco_2nd+'_genbin'+str(genbin)+'_recobin'+str(recobin) - else: - processBin = '_'+i+'_'+channel+'_'+obs_reco+'_genbin'+str(genbin)+'_recobin'+str(recobin) - - cutobs_reco = (abs(datafr[obs_reco]) >= obs_reco_low) & (abs(datafr[obs_reco]) < obs_reco_high) - cutobs_reco_qqzz = (abs(datafr_qqzz[obs_reco]) >= obs_reco_low) & (abs(datafr_qqzz[obs_reco]) < obs_reco_high) - cutobs_reco_ggzz = (abs(datafr_ggzz[obs_reco]) >= obs_reco_low) & (abs(datafr_ggzz[obs_reco]) < obs_reco_high) - cutobs_reco_jesup = (abs(datafr[obs_reco+'_jesup_'+i]) >= obs_reco_low) & (abs(datafr[obs_reco+'_jesup_'+i]) < obs_reco_high) - cutobs_reco_jesdn = (abs(datafr[obs_reco+'_jesdn_'+i]) >= obs_reco_low) & (abs(datafr[obs_reco+'_jesdn_'+i]) < obs_reco_high) - cutobs_reco_jesup_qqzz = (abs(datafr_qqzz[obs_reco+'_jesup_'+i]) >= obs_reco_low) & (abs(datafr_qqzz[obs_reco+'_jesup_'+i]) < obs_reco_high) - cutobs_reco_jesdn_qqzz = (abs(datafr_qqzz[obs_reco+'_jesdn_'+i]) >= obs_reco_low) & (abs(datafr_qqzz[obs_reco+'_jesdn_'+i]) < obs_reco_high) - cutobs_reco_jesup_ggzz = (abs(datafr_ggzz[obs_reco+'_jesup_'+i]) >= obs_reco_low) & (abs(datafr_ggzz[obs_reco+'_jesup_'+i]) < obs_reco_high) - cutobs_reco_jesdn_ggzz = (abs(datafr_ggzz[obs_reco+'_jesdn_'+i]) >= obs_reco_low) & (abs(datafr_ggzz[obs_reco+'_jesdn_'+i]) < obs_reco_high) - - cutobs_gen = (abs(datafr[obs_gen]) >= obs_gen_low) & (abs(datafr[obs_gen]) < obs_gen_high) - if doubleDiff: - cutobs_reco &= (abs(datafr[obs_reco_2nd]) >= obs_reco_2nd_low) & (abs(datafr[obs_reco_2nd]) < obs_reco_2nd_high) - cutobs_reco_jesup &= (abs(datafr[obs_reco_2nd+'_jesup_'+i]) >= obs_reco_2nd_low) & (abs(datafr[obs_reco_2nd+'_jesup_'+i]) < obs_reco_2nd_high) - cutobs_reco_jesdn &= (abs(datafr[obs_reco_2nd+'_jesdn_'+i]) >= obs_reco_2nd_low) & (abs(datafr[obs_reco_2nd+'_jesdn_'+i]) < obs_reco_2nd_high) - cutobs_reco_jesup_qqzz &= (abs(datafr_qqzz[obs_reco_2nd+'_jesup_'+i]) >= obs_reco_low) & (abs(datafr_qqzz[obs_reco_2nd+'_jesup_'+i]) < obs_reco_high) - cutobs_reco_jesdn_qqzz &= (abs(datafr_qqzz[obs_reco_2nd+'_jesdn_'+i]) >= obs_reco_low) & (abs(datafr_qqzz[obs_reco_2nd+'_jesdn_'+i]) < obs_reco_high) - cutobs_reco_jesup_ggzz &= (abs(datafr_ggzz[obs_reco_2nd+'_jesup_'+i]) >= obs_reco_low) & (abs(datafr_ggzz[obs_reco_2nd+'_jesup_'+i]) < obs_reco_high) - cutobs_reco_jesdn_ggzz &= (abs(datafr_ggzz[obs_reco_2nd+'_jesdn_'+i]) >= obs_reco_low) & (abs(datafr_ggzz[obs_reco_2nd+'_jesdn_'+i]) < obs_reco_high) - cutobs_gen &= (abs(datafr[obs_gen_2nd]) >= obs_gen_2nd_low) & (abs(datafr[obs_gen_2nd]) < obs_gen_2nd_high) - - cutobs_gen_otherfid = ((abs(datafr[obs_gen]) >= obs_gen_lowest) & (abs(datafr[obs_gen]) < obs_gen_low)) | ((abs(datafr[obs_gen]) >= obs_gen_high) & (abs(datafr[obs_gen]) <= obs_gen_highest)) - if doubleDiff: - cutobs_gen_otherfid |= ((abs(datafr[obs_gen_2nd]) >= obs_gen_2nd_lowest) & (abs(datafr[obs_gen_2nd]) < obs_gen_2nd_low)) | ((abs(datafr[obs_gen_2nd]) >= obs_gen_2nd_high) & (abs(datafr[obs_gen_2nd]) <= obs_gen_2nd_highest)) - cutm4l_gen = (datafr['GENmass4l'] > m4l_low) & (datafr['GENmass4l'] < m4l_high) - cutnotm4l_gen = (datafr['GENmass4l'] <= m4l_low) | (datafr['GENmass4l'] >= m4l_high) - cuth4l_gen = datafr['cuth4l_gen'] == True - cutnoth4l_gen = datafr['cuth4l_gen'] == False - cuth4l_reco = datafr['cuth4l_reco'] == True - cutnoth4l_reco = datafr['cuth4l_reco'] == False - passedFullSelection = datafr['FinState_reco'] != 'fail' - passedFiducialSelection = datafr['passedFiducialSelection_bbf'] == True - notPassedFiducialSelection = datafr['passedFiducialSelection_bbf'] == False - if channel != '4l': - cutm4l_reco = (datafr['ZZMass'] > m4l_low) & (datafr['ZZMass'] < m4l_high) & (datafr['FinState_reco'] == channel) - cutm4l_reco_qqzz = (datafr_qqzz['ZZMass'] > m4l_low) & (datafr_qqzz['ZZMass'] < m4l_high) - cutm4l_reco_ggzz = (datafr_ggzz['ZZMass'] > m4l_low) & (datafr_ggzz['ZZMass'] < m4l_high) - cutchan_reco_qqzz = datafr_qqzz['FinState_reco'] == channel - cutchan_reco_ggzz = datafr_ggzz['FinState_reco'] == channel - cutchan_gen = datafr['FinState_gen'] == channel - cutchan_gen_out = datafr['FinState_gen_out'] == channel - else: - cutm4l_reco = (datafr['ZZMass'] > m4l_low) & (datafr['ZZMass'] < m4l_high) - cutm4l_reco_qqzz = (datafr_qqzz['ZZMass'] > m4l_low) & (datafr_qqzz['ZZMass'] < m4l_high) - cutm4l_reco_ggzz = (datafr_ggzz['ZZMass'] > m4l_low) & (datafr_ggzz['ZZMass'] < m4l_high) - cutchan_gen = (datafr['FinState_gen'] == '2e2mu') | (datafr['FinState_gen'] == '4e') | (datafr['FinState_gen'] == '4mu') - cutchan_reco_qqzz = (datafr_qqzz['FinState_reco'] == '2e2mu') | (datafr_qqzz['FinState_reco'] == '4e') | (datafr_qqzz['FinState_reco'] == '4mu') - cutchan_reco_ggzz = (datafr_ggzz['FinState_reco'] == '2e2mu') | (datafr_ggzz['FinState_reco'] == '4e') | (datafr_ggzz['FinState_reco'] == '4mu') - cutchan_gen_out = (datafr['FinState_gen_out'] == '2e2mu') | (datafr['FinState_gen_out'] == '4e') | (datafr['FinState_gen_out'] == '4mu') - - - # --------------- Fiducial events --------------- - evts['fiducial'+processBin] = datafr[cutm4l_reco & cutobs_reco & passedFullSelection & cuth4l_reco & - passedFiducialSelection & cuth4l_gen & cutm4l_gen & cutchan_gen & cutobs_gen]['weight_reco'].sum() - evts['fiducial_jesup'+processBin] = datafr[cutm4l_reco & cutobs_reco_jesup & passedFullSelection & cuth4l_reco & - passedFiducialSelection & cuth4l_gen & cutm4l_gen & cutchan_gen & cutobs_gen]['weight_reco'].sum() - evts['fiducial_jesdn'+processBin] = datafr[cutm4l_reco & cutobs_reco_jesdn & passedFullSelection & cuth4l_reco & - passedFiducialSelection & cuth4l_gen & cutm4l_gen & cutchan_gen & cutobs_gen]['weight_reco'].sum() - - if evts['fiducial'+processBin] == 0: - ratio['fiducial'+processBin] = '-' - else: - dn_ratio = round(evts['fiducial_jesdn'+processBin]/evts['fiducial'+processBin],3) - # if dn_ratio == 1.000: dn_ratio = '-' - up_ratio = round(evts['fiducial_jesup'+processBin]/evts['fiducial'+processBin],3) - # if up_ratio == 1.000: up_ratio = '-' - - if up_ratio==dn_ratio and up_ratio==1.000: ratio['fiducial'+processBin] = '-' - elif up_ratio == dn_ratio: ratio['fiducial'+processBin] = str(dn_ratio) - else : ratio['fiducial'+processBin] = str(dn_ratio)+'/'+str(up_ratio) - - if genbin!=recobin: continue #Non-fiducial events, non-resonant, and bkgs events do not depend on the genbin - - # --------------- Non fiducial events --------------- - evts['nonFiducial'+processBin] = datafr[cutm4l_reco & cutobs_reco & passedFullSelection & - cuth4l_reco & cutchan_gen_out & (notPassedFiducialSelection | cutnoth4l_gen | cutnotm4l_gen)]['weight_reco'].sum() - evts['nonFiducial_jesup'+processBin] = datafr[cutm4l_reco & cutobs_reco_jesup & passedFullSelection & - cuth4l_reco & cutchan_gen_out & (notPassedFiducialSelection | cutnoth4l_gen | cutnotm4l_gen)]['weight_reco'].sum() - evts['nonFiducial_jesdn'+processBin] = datafr[cutm4l_reco & cutobs_reco_jesdn & passedFullSelection & - cuth4l_reco & cutchan_gen_out & (notPassedFiducialSelection | cutnoth4l_gen | cutnotm4l_gen)]['weight_reco'].sum() - - if evts['nonFiducial'+processBin] == 0: - ratio['nonFiducial'+processBin] = '-' + processBin = '_'+i+'_'+channel+'_'+str(year)+'_'+obs_reco+'_'+obs_reco_2nd+'_recobin'+str(recobin) else: - dn_ratio = round(evts['nonFiducial_jesdn'+processBin]/evts['nonFiducial'+processBin],3) - # if dn_ratio == 1.000: dn_ratio = '-' - up_ratio = round(evts['nonFiducial_jesup'+processBin]/evts['nonFiducial'+processBin],3) - # if up_ratio == 1.000: up_ratio = '-' - ratio['nonFiducial'+processBin] = str(dn_ratio)+'/'+str(up_ratio) - - if up_ratio==dn_ratio and up_ratio==1.000: ratio['nonFiducial'+processBin] = '-' - elif up_ratio == dn_ratio: ratio['nonFiducial'+processBin] = str(dn_ratio) - else : ratio['nonFiducial'+processBin] = str(dn_ratio)+'/'+str(up_ratio) - - # --------------- Non resonant events --------------- - evts['nonResonant'+processBin] = datafr[passedFullSelection & cutm4l_reco & cutnoth4l_reco & cutobs_reco]['weight_reco'].sum() - evts['nonResonant_jesup'+processBin] = datafr[passedFullSelection & cutm4l_reco & cutnoth4l_reco & cutobs_reco_jesup]['weight_reco'].sum() - evts['nonResonant_jesdn'+processBin] = datafr[passedFullSelection & cutm4l_reco & cutnoth4l_reco & cutobs_reco_jesdn]['weight_reco'].sum() - - if evts['nonResonant'+processBin] == 0: - ratio['nonResonant'+processBin] = '-' - else: - dn_ratio = round(evts['nonResonant_jesdn'+processBin]/evts['nonResonant'+processBin],3) - # if dn_ratio == 1.000: dn_ratio = '-' - up_ratio = round(evts['nonResonant_jesup'+processBin]/evts['nonResonant'+processBin],3) - # if up_ratio == 1.000: up_ratio = '-' - ratio['nonResonant'+processBin] = str(dn_ratio)+'/'+str(up_ratio) + processBin = '_'+i+'_'+channel+'_'+str(year)+'_'+obs_reco+'_recobin'+str(recobin) + + cutobs_reco = (datafr[obs_reco] >= obs_reco_low) & (datafr[obs_reco] < obs_reco_high) + cutobs_reco_qqzz = (datafr_qqzz[obs_reco] >= obs_reco_low) & (datafr_qqzz[obs_reco] < obs_reco_high) + cutobs_reco_ggzz = (datafr_ggzz[obs_reco] >= obs_reco_low) & (datafr_ggzz[obs_reco] < obs_reco_high) + cutobs_reco_jesup = (datafr[obs_reco+'_jesup_'+i] >= obs_reco_low) & (datafr[obs_reco+'_jesup_'+i] < obs_reco_high) + cutobs_reco_jesdn = (datafr[obs_reco+'_jesdn_'+i] >= obs_reco_low) & (datafr[obs_reco+'_jesdn_'+i] < obs_reco_high) + cutobs_reco_jesup_qqzz = (datafr_qqzz[obs_reco+'_jesup_'+i] >= obs_reco_low) & (datafr_qqzz[obs_reco+'_jesup_'+i] < obs_reco_high) + cutobs_reco_jesdn_qqzz = (datafr_qqzz[obs_reco+'_jesdn_'+i] >= obs_reco_low) & (datafr_qqzz[obs_reco+'_jesdn_'+i] < obs_reco_high) + cutobs_reco_jesup_ggzz = (datafr_ggzz[obs_reco+'_jesup_'+i] >= obs_reco_low) & (datafr_ggzz[obs_reco+'_jesup_'+i] < obs_reco_high) + cutobs_reco_jesdn_ggzz = (datafr_ggzz[obs_reco+'_jesdn_'+i] >= obs_reco_low) & (datafr_ggzz[obs_reco+'_jesdn_'+i] < obs_reco_high) - if up_ratio==dn_ratio and up_ratio==1.000: ratio['nonResonant'+processBin] = '-' - elif up_ratio == dn_ratio: ratio['nonResonant'+processBin] = str(dn_ratio) - else : ratio['nonResonant'+processBin] = str(dn_ratio)+'/'+str(up_ratio) + if doubleDiff: + cutobs_reco &= (datafr[obs_reco_2nd] >= obs_reco_2nd_low) & (datafr[obs_reco_2nd] < obs_reco_2nd_high) + cutobs_reco_jesup &= (datafr[obs_reco_2nd+'_jesup_'+i] >= obs_reco_2nd_low) & (datafr[obs_reco_2nd+'_jesup_'+i] < obs_reco_2nd_high) + cutobs_reco_jesdn &= (datafr[obs_reco_2nd+'_jesdn_'+i] >= obs_reco_2nd_low) & (datafr[obs_reco_2nd+'_jesdn_'+i] < obs_reco_2nd_high) + cutobs_reco_jesup_qqzz &= (datafr_qqzz[obs_reco_2nd+'_jesup_'+i] >= obs_reco_2nd_low) & (datafr_qqzz[obs_reco_2nd+'_jesup_'+i] < obs_reco_2nd_high) + cutobs_reco_jesdn_qqzz &= (datafr_qqzz[obs_reco_2nd+'_jesdn_'+i] >= obs_reco_2nd_low) & (datafr_qqzz[obs_reco_2nd+'_jesdn_'+i] < obs_reco_2nd_high) + cutobs_reco_jesup_ggzz &= (datafr_ggzz[obs_reco_2nd+'_jesup_'+i] >= obs_reco_2nd_low) & (datafr_ggzz[obs_reco_2nd+'_jesup_'+i] < obs_reco_2nd_high) + cutobs_reco_jesdn_ggzz &= (datafr_ggzz[obs_reco_2nd+'_jesdn_'+i] >= obs_reco_2nd_low) & (datafr_ggzz[obs_reco_2nd+'_jesdn_'+i] < obs_reco_2nd_high) + + cutm4l_reco = (datafr['ZZMass'] > m4l_low) & (datafr['ZZMass'] < m4l_high) & (datafr['FinState_reco'] == channel) + cutm4l_reco_qqzz = (datafr_qqzz['ZZMass'] > m4l_low) & (datafr_qqzz['ZZMass'] < m4l_high) & (datafr_qqzz['FinState_reco'] == channel) + cutm4l_reco_ggzz = (datafr_ggzz['ZZMass'] > m4l_low) & (datafr_ggzz['ZZMass'] < m4l_high) & (datafr_ggzz['FinState_reco'] == channel) + + # --------------- signal events --------------- + evts['signal'+processBin] = datafr[cutm4l_reco & cutobs_reco]['weight_histo_reco'].sum() + evts['signal_jesup'+processBin] = datafr[cutm4l_reco & cutobs_reco_jesup]['weight_histo_reco'].sum() + evts['signal_jesdn'+processBin] = datafr[cutm4l_reco & cutobs_reco_jesdn]['weight_histo_reco'].sum() + evts_noWeight['signal'+processBin] = len(datafr[cutm4l_reco & cutobs_reco]['weight_histo_reco']) + evts_noWeight['signal_jesup'+processBin] = len(datafr[cutm4l_reco & cutobs_reco_jesup]) + evts_noWeight['signal_jesdn'+processBin] = len(datafr[cutm4l_reco & cutobs_reco_jesdn]) + + ratio['signal'+processBin] = computeRatio(evts['signal'+processBin], evts['signal_jesup'+processBin], evts['signal_jesdn'+processBin]) # --------------- qqzz events --------------- - evts['qqzz'+processBin] = datafr_qqzz[cutm4l_reco_qqzz & cutobs_reco_qqzz & cutchan_reco_qqzz]['weight_reco'].sum() - evts['qqzz_jesup'+processBin] = datafr_qqzz[cutm4l_reco_qqzz & cutobs_reco_jesup_qqzz & cutchan_reco_qqzz]['weight_reco'].sum() - evts['qqzz_jesdn'+processBin] = datafr_qqzz[cutm4l_reco_qqzz & cutobs_reco_jesdn_qqzz & cutchan_reco_qqzz]['weight_reco'].sum() + evts['qqzz'+processBin] = datafr_qqzz[cutm4l_reco_qqzz & cutobs_reco_qqzz]['weight_histo_reco'].sum() + evts['qqzz_jesup'+processBin] = datafr_qqzz[cutm4l_reco_qqzz & cutobs_reco_jesup_qqzz]['weight_histo_reco'].sum() + evts['qqzz_jesdn'+processBin] = datafr_qqzz[cutm4l_reco_qqzz & cutobs_reco_jesdn_qqzz]['weight_histo_reco'].sum() + evts_noWeight['qqzz'+processBin] = len(datafr_qqzz[cutm4l_reco_qqzz & cutobs_reco_qqzz]['weight_histo_reco']) + evts_noWeight['qqzz_jesup'+processBin] = len(datafr_qqzz[cutm4l_reco_qqzz & cutobs_reco_jesup_qqzz]) + evts_noWeight['qqzz_jesdn'+processBin] = len(datafr_qqzz[cutm4l_reco_qqzz & cutobs_reco_jesdn_qqzz]) - if evts['qqzz'+processBin] == 0: - ratio['qqzz'+processBin] = '-' - else: - dn_ratio = round(evts['qqzz_jesdn'+processBin]/evts['qqzz'+processBin],3) - # if dn_ratio == 1.000: dn_ratio = '-' - up_ratio = round(evts['qqzz_jesup'+processBin]/evts['qqzz'+processBin],3) - # if up_ratio == 1.000: up_ratio = '-' - ratio['qqzz'+processBin] = str(dn_ratio)+'/'+str(up_ratio) - - if up_ratio==dn_ratio and up_ratio==1.000: ratio['qqzz'+processBin] = '-' - elif up_ratio == dn_ratio: ratio['qqzz'+processBin] = str(dn_ratio) - else : ratio['qqzz'+processBin] = str(dn_ratio)+'/'+str(up_ratio) + ratio['qqzz'+processBin] = computeRatio(evts['qqzz'+processBin], evts['qqzz_jesup'+processBin], evts['qqzz_jesdn'+processBin]) # --------------- ggzz events --------------- - evts['ggzz'+processBin] = datafr_ggzz[cutm4l_reco_ggzz & cutobs_reco_ggzz & cutchan_reco_ggzz]['weight_reco'].sum() - evts['ggzz_jesup'+processBin] = datafr_ggzz[cutm4l_reco_ggzz & cutobs_reco_jesup_ggzz & cutchan_reco_ggzz]['weight_reco'].sum() - evts['ggzz_jesdn'+processBin] = datafr_ggzz[cutm4l_reco_ggzz & cutobs_reco_jesdn_ggzz & cutchan_reco_ggzz]['weight_reco'].sum() + evts['ggzz'+processBin] = datafr_ggzz[cutm4l_reco_ggzz & cutobs_reco_ggzz]['weight_histo_reco'].sum() + evts['ggzz_jesup'+processBin] = datafr_ggzz[cutm4l_reco_ggzz & cutobs_reco_jesup_ggzz]['weight_histo_reco'].sum() + evts['ggzz_jesdn'+processBin] = datafr_ggzz[cutm4l_reco_ggzz & cutobs_reco_jesdn_ggzz]['weight_histo_reco'].sum() + evts_noWeight['ggzz'+processBin] = len(datafr_ggzz[cutm4l_reco_ggzz & cutobs_reco_ggzz]) + evts_noWeight['ggzz_jesup'+processBin] = len(datafr_ggzz[cutm4l_reco_ggzz & cutobs_reco_jesup_ggzz]) + evts_noWeight['ggzz_jesdn'+processBin] = len(datafr_ggzz[cutm4l_reco_ggzz & cutobs_reco_jesdn_ggzz]) - if evts['ggzz'+processBin] == 0: - ratio['ggzz'+processBin] = '-' - else: - dn_ratio = round(evts['ggzz_jesdn'+processBin]/evts['ggzz'+processBin],3) - # if dn_ratio == 1.000: dn_ratio = '-' - up_ratio = round(evts['ggzz_jesup'+processBin]/evts['ggzz'+processBin],3) - # if up_ratio == 1.000: up_ratio = '-' - ratio['ggzz'+processBin] = str(dn_ratio)+'/'+str(up_ratio) - - if up_ratio==dn_ratio and up_ratio==1.000: ratio['ggzz'+processBin] = '-' - elif up_ratio == dn_ratio: ratio['ggzz'+processBin] = str(dn_ratio) - else : ratio['ggzz'+processBin] = str(dn_ratio)+'/'+str(up_ratio) + ratio['ggzz'+processBin] = computeRatio(evts['ggzz'+processBin], evts['ggzz_jesup'+processBin], evts['ggzz_jesdn'+processBin]) def doGetJes(obs_reco, obs_gen, obs_name, obs_bins, obs_reco_2nd = 'None', obs_gen_2nd = 'None', obs_name_2nd = 'None',): - if obs_reco != 'ZZMass': - chans = ['4e', '4mu', '2e2mu'] - else: - chans = ['4l', '4e', '4mu', '2e2mu'] + chans = ['4e', '4mu', '2e2mu'] m4l_low = 105 m4l_high = 140 @@ -393,8 +179,8 @@ def doGetJes(obs_reco, obs_gen, obs_name, obs_bins, obs_reco_2nd = 'None', obs_g for year in years: for chan in chans: for recobin in range(nBins): - for genbin in range(nBins): - getJes(chan, m4l_low, m4l_high, obs_reco, obs_gen, obs_bins, recobin, genbin, obs_name, year, obs_reco_2nd, obs_gen_2nd, obs_name_2nd) + getJes(chan, m4l_low, m4l_high, obs_reco, obs_gen, obs_bins, recobin, obs_name, year, obs_reco_2nd, obs_gen_2nd, obs_name_2nd) + with open('JESNP_'+obsname_out+'_'+str(year)+'.py', 'w') as f: f.write('obsbins = ' + str(obs_bins) + '\n') @@ -440,8 +226,7 @@ def doGetJes(obs_reco, obs_gen, obs_name, obs_bins, obs_reco_2nd = 'None', obs_g print (obsname, years, m4l_low, m4l_high, obsname_out) -obs_bins, doubleDiff = binning(opt.OBSBINS) - +obs_bins, doubleDiff = binning(opt.OBSNAME) # Generate dataframes d_sig = {} @@ -458,64 +243,16 @@ def doGetJes(obs_reco, obs_gen, obs_name, obs_bins, obs_reco_2nd = 'None', obs_g ratio = {} # Dict with ratio of jesup and jesdown variations wrt nominal value -evts = {} # Dict with number of events for each process +evts = {} # Dict with number of weighted events for each process +evts_noWeight = {} # Dict with number of events for each process if not doubleDiff: doGetJes(obs_reco, obs_gen, obsname, obs_bins) else: doGetJes(obs_reco, obs_gen, obsname, obs_bins, obs_reco_2nd, obsname_2nd) +with open('JESNP_'+obsname_out+'.py', 'w') as f: + f.write('obsbins = ' + str(obs_bins) + '\n') + f.write('JESNP = ' + str(ratio) + '\n') -''' -# Check if the folder for tables exist -if not os.path.exists('tables/'+obsname_out): - os.makedirs('tables/'+obsname_out) -# Tables with numerical values -tables = {} -for index, jesName in enumerate(jesNames): - for fState in ['2e2mu', '4e', '4mu']: - print(jesName,fState) - # Indices to print nonFiducial and nonResonant contribution only once per bin - nonIndex = [(index*3)+k+1 for k in range(0,len(ratio)-1,36*len(obs_bins))] + [(index*3)+k+2 for k in range(0,len(ratio)-1,36*len(obs_bins))] - nonIndex.sort() - - table = [] - nominal_incl = 0 - up_incl = 0 - dn_incl = 0 - for i in range(0,len(ratio)-1): - if not (jesName in list(evts.keys())[i*3] and fState in list(evts.keys())[i*3] and jesName in list(evts.keys())[i*3] and not jesName+'_year' in list(evts.keys())[i*3]): continue - if 'fiducial' in list(evts.keys())[i*3]: - nominal_incl += list(evts.values())[i*3] - up_incl += list(evts.values())[i*3+1] - dn_incl += list(evts.values())[i*3+2] - table.append([list(evts.keys())[i*3], list(evts.values())[i*3], list(evts.values())[i*3+1], list(evts.values())[i*3+2], list(ratio.values())[i]]) - if 'genbin'+str(len(obs_bins)-1) in list(evts.keys())[i*3]: - table.append(['inclusive', nominal_incl, up_incl, dn_incl, str(round(dn_incl/nominal_incl,3))+'/'+str(round(up_incl/nominal_incl,3))]) - nominal_incl = 0 - up_incl = 0 - dn_incl = 0 - if not 'recobin'+str(len(obs_bins)-1) in list(evts.keys())[i*3]: table.append([]) - if i in nonIndex: - nominal_incl += list(evts.values())[i*3] - up_incl += list(evts.values())[i*3+1] - dn_incl += list(evts.values())[i*3+2] - table.append([list(evts.keys())[i*3], list(evts.values())[i*3], list(evts.values())[i*3+1], list(evts.values())[i*3+2], list(ratio.values())[i]]) - tables[jesName,fState] = tabulate(table, headers=['bin', 'nominal', 'jes_up', 'jes_dn', 'ratio(dn/up)'], numalign="right", tablefmt="github") - # print(tables[jesName,fState],'\n') - - with open('tables/JESNP_table_'+obsname_out+'_'+str(year)+'_'+jesName+'_'+fState+'.py', 'w') as f: - f.write(tables[jesName,fState]) - -''' -# jesNP = {} -# if not doubleDiff: -# for year in years: -# for fState in ['2e2mu', '4mu' ,'4e','4l']: -# # year = str(year) -# computeJES(obs_reco, obs_bins, year, fState, m4l_low, m4l_high) -# else: -# for year in years: -# for fState in ['2e2mu', '4mu' ,'4e','4l']: -# computeJES_2D(obs_reco, obs_reco_2nd, obs_bins, year, fState, m4l_low, m4l_high) -# -# with open('../../inputs/JESNP_'+obsname_out+'.py', 'w') as f: -# f.write('obsbins = ' + str(obs_bins) + '\n') -# f.write('JESNP = ' + str(jesNP) + '\n') +with open('JESNP_evts_'+obsname_out+'.py', 'w') as f: + f.write('obsbins = ' + str(obs_bins) + '\n') + f.write('evts = ' + str(evts) + '\n') + f.write('evts_noWeight = ' + str(evts_noWeight) + '\n') \ No newline at end of file diff --git a/coefficients/JES/zx.py b/coefficients/JES/zx.py index 74f619f..00ab851 100644 --- a/coefficients/JES/zx.py +++ b/coefficients/JES/zx.py @@ -1,8 +1,8 @@ import numpy as np import pandas as pd -# import uproot3 as uproot -import uproot +import uproot3 as uproot from math import sqrt, log +import math import ROOT # from config import * @@ -10,10 +10,10 @@ eos_path = '/eos/cms/store/group/phys_higgs/cmshzz4l/cjlst/RunIILegacy/200205_CutBased/' #it is used for FR branches_ZX = ['ZZMass', 'Z1Flav', 'Z2Flav', 'LepLepId', 'LepEta', 'LepPt', 'Z1Mass', 'Z2Mass', 'ZZPt', 'ZZEta', 'helcosthetaZ1','helcosthetaZ2', 'helphi', 'costhetastar', 'phistarZ1', 'ZZPhi', - 'pTj1', 'pTj2', + 'pTj1', 'pTj2', 'absdetajj', 'JetPt_JESUp','JetPt_JESDown','JetEta','JetPhi','JetMass', 'pTHj', 'pTHjj', 'mHj', 'mHjj', 'detajj', 'dphijj', 'mjj', 'njets_pt30_eta2p5', 'ZZy', - 'D0m', 'Dcp', 'D0hp', 'Dint', 'DL1', 'DL1int', 'DL1Zg', 'DL1Zgint'] + 'D0m', 'Dcp', 'D0hp', 'Dint', 'DL1', 'DL1int', 'DL1Zg', 'DL1Zgint', 'TCjmax', 'TBjmax'] def add_leadjet(pt,eta,phi,mass): _pTj1 = 0.0 @@ -26,7 +26,7 @@ def add_leadjet(pt,eta,phi,mass): _j.SetPtEtaPhiM(0,0,0,0) else: for i in range(len(pt)): - if (pt[i]>30 and abs(eta[i])<2.5 and pt[i] > _pTj1): + if (pt[i]>30 and abs(eta[i])<4.7 and pt[i] > _pTj1): _pTj1 = pt[i] index = i _j.SetPtEtaPhiM(_pTj1,eta[index],phi[index],mass[index]) @@ -40,7 +40,7 @@ def add_subleadjet(pt,eta,phi,mass,leadJet): _phij2 = 0.0 _j = ROOT.TLorentzVector() for i in range(len(pt)): - if (pt[i]>30 and abs(eta[i])<2.5 and pt[i] > _pTj2 and leadJet.Pt()-pt[i] > 0.00001): + if (pt[i]>30 and abs(eta[i])<4.7 and pt[i] > _pTj2 and leadJet.Pt()-pt[i] > 0.00001): _pTj2 = pt[i] _mj2 = mass[i] _etaj2 = eta[i] @@ -62,6 +62,24 @@ def FindFinalState_reco(flav): elif flav == 1: return '4mu' else: return '2e2mu' +def tc(pt,eta,phi,mass,H): + _TCjmax = 0 + for i in range(len(pt)): + theJet = ROOT.TLorentzVector() + theJet.SetPtEtaPhiM(pt[i],eta[i],phi[i],mass[i]); + _TCj = sqrt(theJet.Pt()**2 + theJet.M()**2)/(2*math.cosh(theJet.Rapidity() - H.Rapidity())) + if _TCj > _TCjmax: _TCjmax = _TCj + return _TCjmax + +def tb(pt,eta,phi,mass,H): + _TBjmax = 0 + for i in range(len(pt)): + theJet = ROOT.TLorentzVector() + theJet.SetPtEtaPhiM(pt[i],eta[i],phi[i],mass[i]); + _TBj = sqrt(theJet.Pt()**2 + theJet.M()**2)*math.exp(-1*(theJet.Rapidity() - H.Rapidity())); + if _TBj > _TBjmax: _TBjmax = _TBj + return _TBjmax + def GetFakeRate(lep_Pt, lep_eta, lep_ID, g_FR_mu_EB, g_FR_mu_EE, g_FR_e_EB, g_FR_e_EE): if(lep_Pt >= 80.): @@ -169,7 +187,7 @@ def ratio(year): def count_jets(pt,eta,phi,mass): n = 0 for i in range(len(pt)): - if pt[i]>30 and abs(eta[i])<2.5: n = n + 1 + if pt[i]>30 and abs(eta[i])<4.7: n = n + 1 return n def tetra_Higgs(mass,eta,phi,pt): @@ -221,16 +239,26 @@ def doZX(year, g_FR_mu_EB, g_FR_mu_EE, g_FR_e_EB, g_FR_e_EE): dfZX['pTj2_jesdn'] = [x.Pt() for x in dfZX['j2_jesdn']] dfZX['njets_pt30_eta2p5_jesup'] = [count_jets(row[0],row[1],row[2],row[3]) for row in dfZX[['JetPt_JESUp','JetEta','JetPhi','JetMass']].values] dfZX['njets_pt30_eta2p5_jesdn'] = [count_jets(row[0],row[1],row[2],row[3]) for row in dfZX[['JetPt_JESDown','JetEta','JetPhi','JetMass']].values] - dfZX['mjj_jesup'] = [(j1+j2).M() for j1,j2 in zip(dfZX['j1_jesup'],dfZX['j2_jesup'])] - dfZX['mjj_jesdn'] = [(j1+j2).M() for j1,j2 in zip(dfZX['j1_jesdn'],dfZX['j2_jesdn'])] - dfZX['pTHj_jesup'] = [(H+j1).Pt() for H,j1 in zip(dfZX['Higgs'],dfZX['j1_jesup'])] - dfZX['pTHj_jesdn'] = [(H+j1).Pt() for H,j1 in zip(dfZX['Higgs'],dfZX['j1_jesdn'])] - dfZX['pTHjj_jesup'] = [(row[0]+row[1]+row[2]).Pt() for row in dfZX[['Higgs','j1_jesup','j2_jesup']].values] - dfZX['pTHjj_jesdn'] = [(row[0]+row[1]+row[2]).Pt() for row in dfZX[['Higgs','j1_jesdn','j2_jesdn']].values] - dfZX['mHj_jesup'] = [(H+j1).M() for H,j1 in zip(dfZX['Higgs'],dfZX['j1_jesup'])] - dfZX['mHj_jesdn'] = [(H+j1).M() for H,j1 in zip(dfZX['Higgs'],dfZX['j1_jesdn'])] - dfZX['mHjj_jesup'] = [(row[0]+row[1]+row[2]).M() for row in dfZX[['Higgs','j1_jesup','j2_jesup']].values] - dfZX['mHjj_jesdn'] = [(row[0]+row[1]+row[2]).M() for row in dfZX[['Higgs','j1_jesdn','j2_jesdn']].values] + dfZX['mjj_jesup'] = [(j1+j2).M() if j2.Pt()>0 else -1 for j1,j2 in zip(dfZX['j1_jesup'],dfZX['j2_jesup'])] + dfZX['mjj_jesdn'] = [(j1+j2).M() if j2.Pt()>0 else -1 for j1,j2 in zip(dfZX['j1_jesdn'],dfZX['j2_jesdn'])] + dfZX['pTHj_jesup'] = [(H+j1).Pt() if j1.Pt()>0 else -1 for H,j1 in zip(dfZX['Higgs'],dfZX['j1_jesup'])] + dfZX['pTHj_jesdn'] = [(H+j1).Pt() if j1.Pt()>0 else -1 for H,j1 in zip(dfZX['Higgs'],dfZX['j1_jesdn'])] + dfZX['pTHjj_jesup'] = [(row[0]+row[1]+row[2]).Pt() if row[2].Pt()>0 else -1 for row in dfZX[['Higgs','j1_jesup','j2_jesup']].values] + dfZX['pTHjj_jesdn'] = [(row[0]+row[1]+row[2]).Pt() if row[2].Pt()>0 else -1 for row in dfZX[['Higgs','j1_jesdn','j2_jesdn']].values] + dfZX['mHj_jesup'] = [(H+j1).M() if j1.Pt()>0 else -1 for H,j1 in zip(dfZX['Higgs'],dfZX['j1_jesup'])] + dfZX['mHj_jesdn'] = [(H+j1).M() if j1.Pt()>0 else -1 for H,j1 in zip(dfZX['Higgs'],dfZX['j1_jesdn'])] + dfZX['mHjj_jesup'] = [(row[0]+row[1]+row[2]).M() if row[2].Pt()>0 else -1 for row in dfZX[['Higgs','j1_jesup','j2_jesup']].values] + dfZX['mHjj_jesdn'] = [(row[0]+row[1]+row[2]).M() if row[2].Pt()>0 else -1 for row in dfZX[['Higgs','j1_jesdn','j2_jesdn']].values] + dfZX['TCjmax_jesup'] = [tc(row[0],row[1],row[2],row[3],row[4]) for row in dfZX[['JetPt_JESUp','JetEta','JetPhi','JetMass','Higgs']].values] + dfZX['TCjmax_jesdn'] = [tc(row[0],row[1],row[2],row[3],row[4]) for row in dfZX[['JetPt_JESDown','JetEta','JetPhi','JetMass','Higgs']].values] + dfZX['TBjmax_jesup'] = [tb(row[0],row[1],row[2],row[3],row[4]) for row in dfZX[['JetPt_JESUp','JetEta','JetPhi','JetMass','Higgs']].values] + dfZX['TBjmax_jesdn'] = [tb(row[0],row[1],row[2],row[3],row[4]) for row in dfZX[['JetPt_JESDown','JetEta','JetPhi','JetMass','Higgs']].values] + dfZX['absdetajj_jesup'] = [abs(j1.Eta()-j2.Eta()) if j2.Pt()>0 else -1 for j1,j2 in zip(dfZX['j1_jesup'],dfZX['j2_jesup'])] + dfZX['absdetajj_jesdn'] = [abs(j1.Eta()-j2.Eta()) if j2.Pt()>0 else -1 for j1,j2 in zip(dfZX['j1_jesdn'],dfZX['j2_jesdn'])] + + dfZX['ZZPt_jesup'] = dfZX['ZZPt'] + dfZX['ZZPt_jesdn'] = dfZX['ZZPt'] + return dfZX #------------------------- Main ------------------------- diff --git a/coefficients/RunCoefficients.py b/coefficients/RunCoefficients.py index 58a9aef..76c9a85 100644 --- a/coefficients/RunCoefficients.py +++ b/coefficients/RunCoefficients.py @@ -3,7 +3,7 @@ import matplotlib.ticker as ticker import numpy as np import pandas as pd -import uproot +import uproot3 as uproot from math import sqrt, log import sys,os import optparse @@ -12,8 +12,10 @@ import ROOT import json -sys.path.append('../inputs/') +# sys.path.append('../inputs/') from observables import observables +from binning import binning +from paths import path print 'Welcome in RunCoefficients!' @@ -43,9 +45,9 @@ def parseOptions(): global opt, args (opt, args) = parser.parse_args() - if (opt.OBSBINS=='' and opt.OBSNAME!='inclusive'): - parser.error('Bin boundaries not specified for differential measurement. Exiting...') - sys.exit() + # if (opt.OBSBINS=='' and opt.OBSNAME!='inclusive'): + # parser.error('Bin boundaries not specified for differential measurement. Exiting...') + # sys.exit() # parse the arguments and options @@ -591,7 +593,7 @@ def doGetCoeff(obs_reco, obs_gen, obs_name, obs_bins, type, obs_reco_2nd = 'None else: signals_original = ['VBFH125', 'ggH125', 'ttH125', 'WminusH125', 'WplusH125', 'ZH125'] signals = ['ggH125', 'VBFH125', 'WH125', 'ZH125', 'ttH125'] -eos_path_sig = '/eos/user/a/atarabin/MC_samples/' +eos_path_sig = path['eos_path_sig'] key = 'candTree' key_failed = 'candTree_failed' @@ -600,75 +602,8 @@ def doGetCoeff(obs_reco, obs_gen, obs_name, obs_bins, type, obs_reco_2nd = 'None if (opt.YEAR == '2018'): years = [2018] if (opt.YEAR == 'Full'): years = [2016,2017,2018] -if not 'vs' in opt.OBSBINS: #It is not a double-differential analysis - obs_bins = {0:(opt.OBSBINS.split("|")[1:(len(opt.OBSBINS.split("|"))-1)]),1:['0','inf']}[opt.OBSBINS=='inclusive'] - obs_bins = [float(i) for i in obs_bins] #Convert a list of str to a list of float - doubleDiff = False - print 'It is a single-differential measurement, binning', obs_bins -else: #It is a double-differential analysis - doubleDiff = True - # The structure of obs_bins is: - # index of the dictionary is the number of the bin - # [obs_bins_low, obs_bins_high, obs_bins_low_2nd, obs_bins_high_2nd] - # The first two entries are the lower and upper bound of the first variable - # The second two entries are the lower and upper bound of the second variable - if opt.OBSBINS.count('vs')==1 and opt.OBSBINS.count('/')>=1: #Situation like this one '|0|1|2|3|20| vs |0|10|20|45|90|250| / |0|10|20|80|250| / |0|20|90|250| / |0|25|250|' - obs_bins_tmp = opt.OBSBINS.split(" vs ") #['|0|1|2|3|20|', '|0|10|20|45|90|250| / |0|10|20|80|250| / |0|20|90|250| / |0|25|250|'] - obs_bins_1st = obs_bins_tmp[0].split('|')[1:len(obs_bins_tmp[0].split('|'))-1] #['0', '1', '2', '3', '20'] - obs_bins_1st = [float(i) for i in obs_bins_1st] #Convert a list of str to a list of float - obs_bins_tmp = obs_bins_tmp[1].split(' / ') #['|0|10|20|45|90|250|', '|0|10|20|80|250|', '|0|20|90|250|', '|0|25|250|'] - obs_bins_2nd = {} - for i in range(len(obs_bins_tmp)): #At the end of the loop -> obs_bins_2nd {0: ['0', '10', '20', '45', '90', '250'], 1: ['0', '10', '20', '80', '250'], 2: ['0', '20', '90', '250'], 3: ['0', '25', '250']} - obs_bins_2nd[i] = obs_bins_tmp[i].split('|')[1:len(obs_bins_tmp[i].split('|'))-1] - obs_bins_2nd[i] = [float(j) for j in obs_bins_2nd[i]] #Convert a list of str to a list of float - obs_bins = {} - k = 0 #Bin index - for i in range(len(obs_bins_1st)-1): - for j in range(len(obs_bins_2nd[i])-1): - obs_bins[k] = [] - obs_bins[k].append(obs_bins_1st[i]) - obs_bins[k].append(obs_bins_1st[i+1]) - obs_bins[k].append(obs_bins_2nd[i][j]) - obs_bins[k].append(obs_bins_2nd[i][j+1]) - k +=1 - elif opt.OBSBINS.count('vs')>1 and opt.OBSBINS.count('/')>1: #Situation like this one '|50|80| vs |10|30| / |50|80| vs |30|60| / |80|110| vs |10|25| / |80|110| vs |25|30|' - obs_bins_tmp = opt.OBSBINS.split(' / ') #['|50|80| vs |10|30|', '|50|80| vs |30|60|', '|80|110| vs |10|25|', '|80|110| vs |25|30|'] - obs_bins_1st={} - obs_bins_2nd={} - obs_bins={} - for i in range(len(obs_bins_tmp)): #At the end of the loop -> obs_bins_1st {0: ['50', '80'], 1: ['50', '80'], 2: ['80', '110'], 3: ['80', '110']} and obs_bins_2nd {0: ['10', '30'], 1: ['30', '60'], 2: ['10', '25'], 3: ['25', '30']} - obs_bins_tmp_bis = obs_bins_tmp[i].split(' vs ') - obs_bins_1st[i] = obs_bins_tmp_bis[0].split('|')[1:len(obs_bins_tmp_bis[0].split('|'))-1] - obs_bins_1st[i] = [float(j) for j in obs_bins_1st[i]] #Convert a list of str to a list of float - obs_bins_2nd[i] = obs_bins_tmp_bis[1].split('|')[1:len(obs_bins_tmp_bis[1].split('|'))-1] - obs_bins_2nd[i] = [float(j) for j in obs_bins_2nd[i]] #Convert a list of str to a list of float - obs_bins[i] = [] - obs_bins[i].append(obs_bins_1st[i][0]) - obs_bins[i].append(obs_bins_1st[i][1]) - obs_bins[i].append(obs_bins_2nd[i][0]) - obs_bins[i].append(obs_bins_2nd[i][1]) - elif opt.OBSBINS.count('vs')==1 and opt.OBSBINS.count('/')==0: #Situation like this one '|0|1|2|3|20| vs |0|10|20|45|90|250|' - obs_bins_tmp = opt.OBSBINS.split(" vs ") #['|0|1|2|3|20|', '|0|10|20|45|90|250|'] - obs_bins_1st = obs_bins_tmp[0].split('|')[1:len(obs_bins_tmp[0].split('|'))-1] #['0', '1', '2', '3', '20'] - obs_bins_1st = [float(i) for i in obs_bins_1st] #Convert a list of str to a list of float - obs_bins_2nd = obs_bins_tmp[1].split('|')[1:len(obs_bins_tmp[1].split('|'))-1] #['0', '10', '20', '45', '90', '250'] - obs_bins_2nd = [float(i) for i in obs_bins_2nd] #Convert a list of str to a list of float - obs_bins = {} - k = 0 #Bin index - for i in range(len(obs_bins_1st)-1): - for j in range(len(obs_bins_2nd)-1): - obs_bins[k] = [] - obs_bins[k].append(obs_bins_1st[i]) - obs_bins[k].append(obs_bins_1st[i+1]) - obs_bins[k].append(obs_bins_2nd[j]) - obs_bins[k].append(obs_bins_2nd[j+1]) - k +=1 - else: - print 'Problem in the definition of the binning' - quit() - print 'It is a double-differential measurement, binning for the 1st variable', obs_bins_1st, 'and for the 2nd variable', obs_bins_2nd - print obs_bins +obs_bins, doubleDiff = binning(opt.OBSNAME) if doubleDiff: obs_name = opt.OBSNAME.split(' vs ')[0] obs_name_2nd = opt.OBSNAME.split(' vs ')[1] diff --git a/coefficients/RunPlotCoefficients.py b/coefficients/RunPlotCoefficients.py index a67e1ac..961c28c 100644 --- a/coefficients/RunPlotCoefficients.py +++ b/coefficients/RunPlotCoefficients.py @@ -29,9 +29,9 @@ def parseOptions(): global opt, args (opt, args) = parser.parse_args() - if (opt.OBSBINS=='' and opt.OBSNAME!='inclusive'): - parser.error('Bin boundaries not specified for differential measurement. Exiting...') - sys.exit() + # if (opt.OBSBINS=='' and opt.OBSNAME!='inclusive'): + # parser.error('Bin boundaries not specified for differential measurement. Exiting...') + # sys.exit() # parse the arguments and options @@ -282,7 +282,7 @@ def nonFid(obs_bins, obs_name, label): elif(obs_name == 'njets_pt30_eta2p5 vs pT4l'): obs_name = 'njets_pt30_eta2p5_pT4l' #Change name of obs_name label = 'N$_{jet}$/p$_T^H$(GeV)' -elif(obs_name == 'massZ1 vs massZ2'): +elif(obs_name == 'massZ1_massZ2'): obs_name = 'massZ1_massZ2' #Change name of obs_name label = 'm$_{Z1}$(GeV)/m$_{Z2}$(GeV)' elif(obs_name == 'D0m'): @@ -299,6 +299,12 @@ def nonFid(obs_bins, obs_name, label): label = 'p$_T^{j1}$ (GeV)' elif(obs_name == 'pTHj'): label = 'p$_T^{Hj}$ (GeV)' +elif(obs_name == 'mass4l'): + label = 'm$_4/ell$ (GeV)' +elif(obs_name == 'mass4l_zzfloating'): + label = 'm$_4/ell$ (GeV)' +else: + label = '' _temp = __import__('inputs_sig_'+obs_name+'_'+opt.YEAR, globals(), locals(), ['observableBins']) # Open file to retrieve the binning obs_bins = _temp.observableBins diff --git a/coefficients/pdfUncertainty.py b/coefficients/pdfUncertainty.py index 1bdbee4..663ef64 100644 --- a/coefficients/pdfUncertainty.py +++ b/coefficients/pdfUncertainty.py @@ -3,7 +3,7 @@ import matplotlib.ticker as ticker import numpy as np import pandas as pd -import uproot +import uproot3 as uproot from math import sqrt, log import sys,os import optparse @@ -12,6 +12,8 @@ import ROOT import json +from paths import path + print 'Welcome in pdfUncertainty!' def parseOptions(): @@ -28,6 +30,8 @@ def parseOptions(): parser.add_option('', '--year', dest='YEAR', type='string',default='', help='Year -> 2016 or 2017 or 2018 or Full') parser.add_option('', '--verbose', action='store_true', dest='VERBOSE', default=False, help='print values') parser.add_option('', '--nnlops', action='store_true', dest='NNLOPS', default=False, help='Calculate uncert for ggH_NNLOPS sample') + parser.add_option('', '--m4lLower', dest='LOWER_BOUND', type='int',default=105.0, help='Lower bound for m4l') + parser.add_option('', '--m4lUpper', dest='UPPER_BOUND', type='int',default=140.0, help='Upper bound for m4l') # store options and arguments as global variables global opt, args (opt, args) = parser.parse_args() @@ -322,12 +326,12 @@ def getPdfUncert(channel, m4l_low, m4l_high, obs_reco, obs_gen, obs_bins, genbin # Selections cutm4l_gen = (datafr['GENmass4l'] > m4l_low) & (datafr['GENmass4l'] < m4l_high) if obs_reco.startswith('njets') and not doubleDiff: - cutobs_gen = abs(datafr[obs_gen]) >= obs_gen_low + cutobs_gen = datafr[obs_gen] >= obs_gen_low else: - cutobs_gen = (abs(datafr[obs_gen]) >= obs_gen_low) & (abs(datafr[obs_gen]) < obs_gen_high) + cutobs_gen = (datafr[obs_gen] >= obs_gen_low) & (datafr[obs_gen] < obs_gen_high) if (obs_name=='Dcp'): cutobs_gen = (datafr[obs_gen] >= obs_gen_low) & (datafr[obs_gen] < obs_gen_high) if doubleDiff: - cutobs_gen &= (abs(datafr[obs_gen_2nd]) >= obs_gen_2nd_low) & (abs(datafr[obs_gen_2nd]) < obs_gen_2nd_high) + cutobs_gen &= (datafr[obs_gen_2nd] >= obs_gen_2nd_low) & (datafr[obs_gen_2nd] < obs_gen_2nd_high) if channel != '4l': cutm4l_reco = (datafr['ZZMass'] > m4l_low) & (datafr['ZZMass'] < m4l_high) & (datafr['FinState_reco'] == channel) cutchan_gen = datafr['FinState_gen'] == channel @@ -404,7 +408,7 @@ def getPdfUncert(channel, m4l_low, m4l_high, obs_reco, obs_gen, obs_bins, genbin # if opt.AC_HYP: signals_original = signals = ['ggH'+opt.AC_HYP+'_M125'] # else: signals_original = signals = ['ggH125'] signals_original = signals = ['ggH125'] -eos_path_sig = '/eos/user/a/atarabin/MC_samples/' +eos_path_sig = path['eos_path_sig'] key = 'candTree' key_failed = 'candTree_failed' verbose = False @@ -426,10 +430,10 @@ def getPdfUncert(channel, m4l_low, m4l_high, obs_reco, obs_gen, obs_bins, genbin else: obs_name = opt.OBSNAME -sys.path.append('../inputs/') +# sys.path.append('../inputs/') _temp = __import__('observables', globals(), locals(), ['observables'], -1) observables = _temp.observables -sys.path.remove('../inputs/') +# sys.path.remove('../inputs/') if doubleDiff: obs_reco = observables[obs_name_2d]['obs_reco'] @@ -478,8 +482,8 @@ def getPdfUncert(channel, m4l_low, m4l_high, obs_reco, obs_gen, obs_bins, genbin chans = ['4e', '4mu', '2e2mu', '4l'] -m4l_low = 105.0 -m4l_high = 140.0 +m4l_low = opt.LOWER_BOUND +m4l_high = opt.UPPER_BOUND acceptance = {} qcdUncert = {} pdfUncert = {} diff --git a/condor_submission/CMSSW_10_2_13_withCombine.tgz b/condor_submission/CMSSW_10_2_13_withCombine.tgz new file mode 100644 index 0000000..7079713 Binary files /dev/null and b/condor_submission/CMSSW_10_2_13_withCombine.tgz differ diff --git a/condor_submission/batchScript.sh b/condor_submission/batchScript.sh new file mode 100644 index 0000000..4faaf09 --- /dev/null +++ b/condor_submission/batchScript.sh @@ -0,0 +1,205 @@ +#!/bin/bash + +## ----- Setting pre-compiled CMSSW version with combine ----- ## +cp /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/condor_submission/CMSSW_10_2_13_withCombine.tgz . +source /cvmfs/cms.cern.ch/cmsset_default.sh +tar -xf CMSSW_10_2_13_withCombine.tgz +rm CMSSW_10_2_13_withCombine.tgz +cd CMSSW_10_2_13/src/ +scramv1 b ProjectRename +eval `scramv1 runtime -sh` + +## ----- Setting kerberos to access EOS area ----- ## +# export KRB5CCNAME=FILE:/etc/krb5c/$(whoami) +# /opt/exp_soft/cms/t3/eos-login -username atarabin + +mkdir coefficients coefficients/matrix_eff coefficients/matrix_eff/2016 coefficients/matrix_eff/2017 coefficients/matrix_eff/2018 coefficients/matrix_nonfid +mkdir combine_files +mkdir datacard datacard/datacard_2016 datacard/datacard_2017 datacard/datacard_2018 +mkdir fit +mkdir inputs +mkdir LHScans LHScans/plots +mkdir templates +mkdir templates/plots templates/plots/2016 templates/plots/2017 templates/plots/2018 +mkdir templates/plots/2016/OBS templates/plots/2017/OBS templates/plots/2018/OBS +mkdir impacts +mkdir helperstuff + +cp /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/helperstuff/binning.py helperstuff/. +cp /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/helperstuff/observables.py helperstuff/. + +cp /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/inputs/higgs_xsbr_13TeV.py inputs/. + +cd coefficients +cp /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/coefficients/RunCoefficients.py . +python RunCoefficients.py --obsName 'VAR' --year 'Full' ZZFLOATING +FIRST +SECOND + +jes=SETTING +if [ $jes == true ];then + mkdir JES JES/tables JES/tables/OBS + cd JES + # cp /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/coefficients/JES/RunJES.py . + cp /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/coefficients/JES/PrintJES.py . + # cp /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/coefficients/JES/zx.py . + cp /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/coefficients/JES/JESNP_OBS.py . + cp /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/coefficients/JES/JESNP_evts_OBS.py . + # python RunJES.py --obsName 'VAR' --year 'Full' + python PrintJES.py --obsName 'VAR' --year '2016' + python PrintJES.py --obsName 'VAR' --year '2017' + python PrintJES.py --obsName 'VAR' --year '2018' + cd .. +fi + +cp /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/coefficients/pdfUncertainty.py . +python pdfUncertainty.py --obsName 'VAR' --year 'Full' ZZFLOATING +# python pdfUncertainty.py --obsName 'VAR' --year 'Full' --nnlops +cd ../inputs +sed "s/ggH125/ggH125_NNLOPS/g" accUnc_OBS.py > accUnc_OBS_NNLOPS.py #FIXME: This is temporary! + +cd ../templates +cp /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/templates/RunTemplates.py . +cp /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/templates/plot_templates.py . +cp /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/templates/tdrStyle.py . +python RunTemplates.py --obsName 'VAR' --year 'Full' ZZFLOATING +# c++ -o plot_templates plot_templates.cpp `root-config --cflags --glibs` +# IN="BIN" +# boundaries=$(echo $IN | tr "|" "\n") +# ./plot_templates OBS $boundaries +python plot_templates.py --obsName 'VAR' --year 'Full' + + +cd ../fit +cp /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/fit/RunFiducialXS.py . +cp /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/fit/createDatacard.py . +cp /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/fit/createXSworkspace.py . +cp /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/fit/addConstrainedModel.py . +cp /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/fit/impacts.py . +python RunFiducialXS.py --obsName 'VAR' --year 'Full' UNBLIND ZZFLOATING +python impacts.py --obsName 'VAR' --year 'Full' UNBLIND +FIFTH UNBLIND + +cd ../LHScans +cp /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/LHScans/plot_LLScan.py . +cp /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/LHScans/plotting.py . +python plot_LLScan.py --obsName 'VAR' --year 'Full' UNBLIND +FOURTH UNBLIND + +cd .. +cp /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/tdrStyle.py . +cp /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/producePlots.py . +cp /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/producePlots_v4.py . +python producePlots.py --obsName 'VAR' --year 'Full' UNBLIND +THIRD UNBLIND + +## ----- Moving all outputs ----- ## +# Outputs from RunCoefficients +mv inputs/inputs_sig_* /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/inputs + +# Outputs from JES +if [ $jes == true ]; then + + # mv inputs/JES* /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/inputs + + # if [ -d /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/coefficients/JES/plots/OBS ]; then + # rm -r /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/coefficients/JES/plots/OBS + # mkdir /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/coefficients/JES/plots/OBS + # else + # mkdir /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/coefficients/JES/plots/OBS + # fi + # mv coefficients/JES/plots/OBS/* /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/coefficients/JES/plots/OBS/. + + if [ -d /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/coefficients/JES/tables/OBS ]; then + rm -r /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/coefficients/JES/tables/OBS + mkdir /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/coefficients/JES/tables/OBS + else + mkdir /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/coefficients/JES/tables/OBS + fi + mv coefficients/JES/tables/OBS/* /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/coefficients/JES/tables/OBS/. + +fi + +# Outputs from pdfUncertainty +mv inputs/accUnc_* /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/inputs + +# Outputs from RunTemplates +mv inputs/inputs_bkg* /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/inputs +if [ -d /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/templates/2016/OBS ]; then + rm -rf /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/templates/2016/OBS + mkdir /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/templates/2016/OBS +else + mkdir /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/templates/2016/OBS +fi +mv templates/2016/OBS/* /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/templates/2016/OBS/. +if [ -d /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/templates/2017/OBS ]; then + rm -rf /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/templates/2017/OBS + mkdir /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/templates/2017/OBS +else + mkdir /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/templates/2017/OBS +fi +mv templates/2017/OBS/* /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/templates/2017/OBS/. +if [ -d /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/templates/2018/OBS ]; then + rm -rf /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/templates/2018/OBS + mkdir /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/templates/2018/OBS +else + mkdir /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/templates/2018/OBS +fi +mv templates/2018/OBS/* /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/templates/2018/OBS/. + +# Outputs from plot_templates +if [ -d /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/templates/plots/2016/OBS ]; then + rm -rf /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/templates/plots/2016/OBS + mkdir /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/templates/plots/2016/OBS +else + mkdir /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/templates/plots/2016/OBS +fi +mv templates/plots/2016/OBS/* /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/templates/plots/2016/OBS/. +if [ -d /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/templates/plots/2017/OBS ]; then + rm -rf /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/templates/plots/2017/OBS + mkdir /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/templates/plots/2017/OBS +else + mkdir /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/templates/plots/2017/OBS +fi +mv templates/plots/2017/OBS/* /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/templates/plots/2017/OBS/. +if [ -d /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/templates/plots/2018/OBS ]; then + rm -rf /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/templates/plots/2018/OBS + mkdir /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/templates/plots/2018/OBS +else + mkdir /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/templates/plots/2018/OBS +fi +mv templates/plots/2018/OBS/* /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/templates/plots/2018/OBS/. + +# Outputs from RunFiducialXS +mv fit/commands_OBS.py /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/fit/. +mv datacard/hzz4l_all_13TeV_xs_* /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/datacard/. +mv datacard/datacard_2016/* /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/datacard/datacard_2016/. +mv datacard/datacard_2017/* /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/datacard/datacard_2017/. +mv datacard/datacard_2018/* /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/datacard/datacard_2018/. + +# Outputs from plot_LLScan.py +mv LHScans/plots/lhscan_compare* /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/LHScans/plots/. +mv LHScans/resultsXS_LHScan_* /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/LHScans/. + +# Outputs from producePlots.py +if [ -d /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/plots/OBS ]; then + rm -rf /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/plots/OBS + mkdir /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/plots/OBS +else + mkdir /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/plots/OBS +fi +mv plots/OBS/* /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/plots/OBS/. + +# Outputs from impacts.py +if [ -d /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/impacts/OBS ]; then + rm -rf /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/impacts/OBS + mkdir /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/impacts/OBS +else + mkdir /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/impacts/OBS +fi +mv impacts/* /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/impacts/OBS/. + +# Combine files +mv combine_files/* /home/llr/cms/tarabini/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXSFWK/combine_files/. + +rm -rf * diff --git a/condor_submission/sub.sh b/condor_submission/sub.sh new file mode 100644 index 0000000..f015700 --- /dev/null +++ b/condor_submission/sub.sh @@ -0,0 +1,192 @@ +#!/bin/bash +# $1 -> true or false to unblind + +declare -a obs=( +# "mass4l noJES" +"mass4l_zzfloating noJES" +# "njets_pt30_eta4p7 JES" +# "pT4l noJES" +# "rapidity4l noJES" +# "costhetaZ1 noJES" +# "costhetaZ2 noJES" +# "phi noJES" +# "phistar noJES" +# "costhetastar noJES" +# "massZ1 noJES" +# "massZ2 noJES" +# "pTj1 JES" +# "pTHj JES" +# "mHj JES" +# "pTj2 JES" +# "mjj JES" +# "absdetajj JES" +# "dphijj JES" +# "pTHjj JES" +# "TCjmax JES" +# "TBjmax JES" +# "D0m noJES" +# "Dcp noJES" +# "D0hp noJES" +# "Dint noJES" +# "DL1 noJES" +# "DL1Zg noJES" +# "rapidity4l vs pT4l noJES" +# "njets_pt30_eta4p7 vs pT4l JES" +# "pTj1 vs pTj2 JES" +# "pT4l vs pTHj JES" +# "massZ1 vs massZ2 noJES" +# "TCjmax vs pT4l JES" +) +source /opt/exp_soft/cms/t3/t3setup + +echo +echo "------------------------------------------------------------" + +for i in "${!obs[@]}"; do + name=($(echo ${obs[$i]} | cut -d" " -f1)) + name_folder=$name + if [ $(echo ${obs[$i]} | cut -d" " -f2) == "vs" ]; then + name=$name" vs "$(echo ${obs[$i]} | cut -d" " -f3) + name_folder=$name_folder"_"$(echo ${obs[$i]} | cut -d" " -f3) + fi + jes=($(echo ${obs[$i]} | rev | cut -d" " -f1 | rev)) + echo + echo "name of the observable:" $name + echo "name of folders:" $name_folder + echo $jes + if [ -d $name_folder ]; then + rm -rf $name_folder + fi + mkdir $name_folder + cd $name_folder + cp ../batchScript.sh . + sed -i "s/OBS/$name_folder/g" batchScript.sh + sed -i "s/VAR/$name/g" batchScript.sh + sed -i "s/BIN/$bins/g" batchScript.sh + + if [ $1 == true ]; then + sed -i "s/asimov/data/g" batchScript.sh + sed -i "s/UNBLIND/--unblind/g" batchScript.sh + else + sed -i "s/UNBLIND//g" batchScript.sh + fi + + #JES flag + if [ $jes == "JES" ]; then + sed -i "s/SETTING/true/g" batchScript.sh + else + sed -i "s/SETTING/false/g" batchScript.sh + fi + + #Compute AC acceptances using AC samples + #-----FIXME:Since AC samples have been processed for 2016 only, little trick to postpone the problem + #-----FIXME:RunCoefficients is run just for 2016 + if [ $name_folder == D0m ]; then + CoeffAC="python RunCoefficients.py --obsName 'D0m' --year '2016' --AC_onlyAcc --AC_hypothesis '0M'" + CoeffACbis="" + plotsv4="python producePlots_v4.py --obsName 'D0m' --year 'Full'" + LLscanv4="python plot_LLScan.py --obsName 'D0m' --year 'Full' --v4" + impactsv4="python impacts.py --obsName 'D0m' --year 'Full' --physicsModel 'v4'" + elif [ $name_folder == Dcp ]; then + CoeffAC="python RunCoefficients.py --obsName 'Dcp' --year '2016' --AC_onlyAcc --AC_hypothesis '0Mf05ph0'" + CoeffACbis="" + plotsv4="python producePlots_v4.py --obsName 'Dcp' --year 'Full'" + LLscanv4="python plot_LLScan.py --obsName 'Dcp' --year 'Full' --v4" + impactsv4="python impacts.py --obsName 'Dcp' --year 'Full' --physicsModel 'v4'" + elif [ $name_folder == D0hp ]; then + CoeffAC="python RunCoefficients.py --obsName 'D0hp' --year '2016' --AC_onlyAcc --AC_hypothesis '0PH'" + CoeffACbis="" + plotsv4="python producePlots_v4.py --obsName 'D0hp' --year 'Full'" + LLscanv4="python plot_LLScan.py --obsName 'D0hp' --year 'Full' --v4" + impactsv4="python impacts.py --obsName 'D0hp' --year 'Full' --physicsModel 'v4'" + elif [ $name_folder == Dint ]; then + CoeffAC="python RunCoefficients.py --obsName 'Dint' --year '2016' --AC_onlyAcc --AC_hypothesis '0PHf05ph0'" + CoeffACbis="" + plotsv4="python producePlots_v4.py --obsName 'Dint' --year 'Full'" + LLscanv4="python plot_LLScan.py --obsName 'Dint' --year 'Full' --v4" + impactsv4="python impacts.py --obsName 'Dint' --year 'Full' --physicsModel 'v4'" + elif [ $name_folder == DL1 ]; then + CoeffAC="python RunCoefficients.py --obsName 'DL1' --year '2016' --AC_onlyAcc --AC_hypothesis '0L1'" + CoeffACbis="python RunCoefficients.py --obsName 'DL1' --year '2016' --AC_onlyAcc --AC_hypothesis '0L1f05ph0'" + plotsv4="python producePlots_v4.py --obsName 'DL1' --year 'Full'" + LLscanv4="python plot_LLScan.py --obsName 'DL1' --year 'Full' --v4" + impactsv4="python impacts.py --obsName 'DL1' --year 'Full' --physicsModel 'v4'" + elif [ $name_folder == DL1Zg ]; then + CoeffAC="python RunCoefficients.py --obsName 'DL1Zg' --year '2016' --AC_onlyAcc --AC_hypothesis '0L1'" + CoeffACbis="python RunCoefficients.py --obsName 'DL1Zg' --year '2016' --AC_onlyAcc --AC_hypothesis '0L1f05ph0'" + plotsv4="python producePlots_v4.py --obsName 'DL1Zg' --year 'Full'" + LLscanv4="python plot_LLScan.py --obsName 'DL1Zg' --year 'Full' --v4" + impactsv4="python impacts.py --obsName 'DL1Zg' --year 'Full' --physicsModel 'v4'" + elif [ $name_folder == massZ1 ]; then + CoeffAC="" + CoeffACbis="" + plotsv4="python producePlots_v4.py --obsName 'massZ1' --year 'Full'" + LLscanv4="python plot_LLScan.py --obsName 'massZ1' --year 'Full' --v4" + impactsv4="python impacts.py --obsName 'massZ1' --year 'Full' --physicsModel 'v4'" + elif [ $name_folder == massZ2 ]; then + CoeffAC="" + CoeffACbis="" + plotsv4="python producePlots_v4.py --obsName 'massZ2' --year 'Full'" + LLscanv4="python plot_LLScan.py --obsName 'massZ2' --year 'Full' --v4" + impactsv4="python impacts.py --obsName 'massZ2' --year 'Full' --physicsModel 'v4'" + elif [ $name_folder == costhetastar ]; then + CoeffAC="" + CoeffACbis="" + plotsv4="python producePlots_v4.py --obsName 'costhetastar' --year 'Full'" + LLscanv4="python plot_LLScan.py --obsName 'costhetastar' --year 'Full' --v4" + impactsv4="python impacts.py --obsName 'costhetastar' --year 'Full' --physicsModel 'v4'" + elif [ $name_folder == costhetaZ1 ]; then + CoeffAC="" + CoeffACbis="" + plotsv4="python producePlots_v4.py --obsName 'costhetaZ1' --year 'Full'" + LLscanv4="python plot_LLScan.py --obsName 'costhetaZ1' --year 'Full' --v4" + impactsv4="python impacts.py --obsName 'costhetaZ1' --year 'Full' --physicsModel 'v4'" + elif [ $name_folder == costhetaZ2 ]; then + CoeffAC="" + CoeffACbis="" + plotsv4="python producePlots_v4.py --obsName 'costhetaZ2' --year 'Full'" + LLscanv4="python plot_LLScan.py --obsName 'costhetaZ2' --year 'Full' --v4" + impactsv4="python impacts.py --obsName 'costhetaZ2' --year 'Full' --physicsModel 'v4'" + elif [ $name_folder == phi ]; then + CoeffAC="" + CoeffACbis="" + plotsv4="python producePlots_v4.py --obsName 'phi' --year 'Full'" + LLscanv4="python plot_LLScan.py --obsName 'phi' --year 'Full' --v4" + impactsv4="python impacts.py --obsName 'phi' --year 'Full' --physicsModel 'v4'" + elif [ $name_folder == phistar ]; then + CoeffAC="" + CoeffACbis="" + plotsv4="python producePlots_v4.py --obsName 'phistar' --year 'Full'" + LLscanv4="python plot_LLScan.py --obsName 'phistar' --year 'Full' --v4" + impactsv4="python impacts.py --obsName 'phistar' --year 'Full' --physicsModel 'v4'" + elif [ $name_folder == mass4l ] || [ $name_folder == mass4l_zzfloating ]; then + CoeffAC="" + CoeffACbis="" + plotsv4="" + LLscanv4="" + impactsv4="python impacts.py --obsName '$name_folder' --year 'Full' --physicsModel 'v2'" #Let's use the same flag for v2 + else + CoeffAC="" + CoeffACbis="" + plotsv4="" + LLscanv4="" + impactsv4="" + fi + sed -i "s/FIRST/$CoeffAC/g" batchScript.sh + sed -i "s/SECOND/$CoeffACbis/g" batchScript.sh + sed -i "s/THIRD/$plotsv4/g" batchScript.sh + sed -i "s/FOURTH/$LLscanv4/g" batchScript.sh + sed -i "s/FIFTH/$impactsv4/g" batchScript.sh + + + if [ $name_folder == mass4l_zzfloating ]; then + zzfloating="--m4lLower 105 --m4lUpper 160" + else + zzfloating="" + fi + sed -i "s/ZZFLOATING/$zzfloating/g" batchScript.sh + + /opt/exp_soft/cms/t3/t3submit batchScript.sh + cd .. + echo +done diff --git a/copy_to_www.sh b/copy_to_www.sh new file mode 100644 index 0000000..06b988e --- /dev/null +++ b/copy_to_www.sh @@ -0,0 +1,66 @@ +#!/bin/bash + +#Check if the name of the observable is provided in the command line +if [[ $# -eq 0 ]] ; then + echo 'no name of the observable is provided' + exit 1 +fi + +path="/eos/user/a/atarabin/www/fiducial/run2_cardsValidation" + +/opt/exp_soft/cms/t3/eos-login -init -username atarabin + +cd coefficients +source /opt/exp_soft/llr/root/vv6.20.06-el7-gcc9-py37/etc/init.sh +python RunPlotCoefficients.py --obsName "${1}" --year 'Full' +cd .. + +if [ -d "$path/${1}" ]; then + ### Take action if $DIR exists ### + rm -r $path/${1} + mkdir $path/${1} + cp $path/index.php $path/${1} +else + ### Control will jump here if $DIR does NOT exists ### + mkdir $path/${1} + cp $path/index.php $path/${1} +fi + +mkdir $path/${1}/datacard_2016 $path/${1}/datacard_2017 $path/${1}/datacard_2018 +cp $path/index.php $path/${1} +cp $path/index.php $path/${1}/datacard_2016 +cp $path/index.php $path/${1}/datacard_2017 +cp $path/index.php $path/${1}/datacard_2018 + +mkdir $path/${1}/templatesBkgs_2016 $path/${1}/templatesBkgs_2017 $path/${1}/templatesBkgs_2018 +cp $path/index.php $path/${1}/templatesBkgs_2016/. +cp $path/index.php $path/${1}/templatesBkgs_2017/. +cp $path/index.php $path/${1}/templatesBkgs_2018/. +mv templates/plots/2016/${1}/* $path/${1}/templatesBkgs_2016/. +mv templates/plots/2017/${1}/* $path/${1}/templatesBkgs_2017/. +mv templates/plots/2018/${1}/* $path/${1}/templatesBkgs_2018/. + +mv coefficients/matrix_eff/2016/eff_2016_${1}_* $path/${1}/. +mv coefficients/matrix_eff/2017/eff_2017_${1}_* $path/${1}/. +mv coefficients/matrix_eff/2018/eff_2018_${1}_* $path/${1}/. + +mv coefficients/matrix_nonfid/2016/nonFid_2016_${1}_* $path/${1}/. +mv coefficients/matrix_nonfid/2017/nonFid_2017_${1}_* $path/${1}/. +mv coefficients/matrix_nonfid/2018/nonFid_2018_${1}_* $path/${1}/. + +# Move datacards +mv datacard/datacard_2016/hzz4l_*_13TeV_xs_${1}_bin*_v* $path/${1}/datacard_2016/. +mv datacard/datacard_2017/hzz4l_*_13TeV_xs_${1}_bin*_v* $path/${1}/datacard_2017/. +mv datacard/datacard_2018/hzz4l_*_13TeV_xs_${1}_bin*_v* $path/${1}/datacard_2018/. +mv datacard/hzz4l_*_13TeV_xs_${1}_bin*_v* $path/${1}/. +# Move ws +mv datacard/datacard_2016/hzz4l_*_13TeV_xs_SM_125_${1}_v* $path/${1}/datacard_2016/. +mv datacard/datacard_2017/hzz4l_*_13TeV_xs_SM_125_${1}_v* $path/${1}/datacard_2017/. +mv datacard/datacard_2018/hzz4l_*_13TeV_xs_SM_125_${1}_v* $path/${1}/datacard_2018/. + +mv plots/${1}/asimov/${1}_unfoldwith* $path/${1}/. +mv impacts/impacts_*_${1}_*_asimov* $path/${1}/. +mv LHScans/plots/lhscan_compare_${1}_* $path/${1}/. + +mv fit/commands_${1}.py $path/${1}/. +mv impacts/commands_impacts_${1}_v* $path/${1}/. diff --git a/fit/RunFiducialXS.py b/fit/RunFiducialXS.py index 58f3e08..6091f5e 100644 --- a/fit/RunFiducialXS.py +++ b/fit/RunFiducialXS.py @@ -43,6 +43,7 @@ def parseOptions(): parser.add_option('', '--combineOnly',action='store_true', dest='combineOnly',default=False, help='Run the measurement only, default is False') parser.add_option('', '--m4lLower', dest='LOWER_BOUND', type='int',default=105.0, help='Lower bound for m4l') parser.add_option('', '--m4lUpper', dest='UPPER_BOUND', type='int',default=140.0, help='Upper bound for m4l') + parser.add_option('', '--ZZfloating',action='store_true', dest='ZZ',default=False, help='Let ZZ normalisation to float') # Unblind option parser.add_option('', '--unblind', action='store_true', dest='UNBLIND', default=False, help='Use real data') # Calculate Systematic Uncertainties @@ -90,9 +91,11 @@ def produceDatacards(obsName, observableBins, ModelName, physicalmodel): fStates = ['2e2mu','4mu','4e'] nBins = len(observableBins) if not doubleDiff: nBins = nBins-1 #in case of 1D measurement the number of bins is -1 the length of the list of bin boundaries - if (('jet' in obsName) | (obsName == 'pTj1')): JES = True - else: JES = False - # JES = False + # if (('pTj1' in obsName) | ('pTHj' in obsName) | ('mHj' in obsName) | ('pTj2' in obsName) | ('mjj' in obsName) | ('absdetajj' in obsName) | ('dphijj' in obsName) | ('pTHjj' in obsName) | ('TCjmax' in obsName) | ('TBjmax' in obsName) | ('njets_pt30_eta4p7' in obsName)): + # JES = True + # else: + # JES = False + # # JES = False os.chdir('../datacard/datacard_'+years[0]) for year in years: os.chdir('../datacard_'+year) @@ -116,14 +119,14 @@ def produceDatacards(obsName, observableBins, ModelName, physicalmodel): def runFiducialXS(): # variable for double-differential measurements and obsName - global doubleDiff - if 'vs' in opt.OBSNAME: - obsName_tmp = opt.OBSNAME.split(' vs ') - obsName = obsName_tmp[0]+'_'+obsName_tmp[1] - doubleDiff = True - else: - obsName = opt.OBSNAME - doubleDiff = False + # global doubleDiff + # if 'vs' in opt.OBSNAME: + # obsName_tmp = opt.OBSNAME.split(' vs ') + # obsName = obsName_tmp[0]+'_'+obsName_tmp[1] + # doubleDiff = True + # else: + # obsName = opt.OBSNAME + # doubleDiff = False _th_MH = opt.THEORYMASS # prepare the set of bin boundaries to run over, it is retrieved from inputs file _temp = __import__('inputs_sig_'+obsName+'_'+opt.YEAR, globals(), locals(), ['observableBins'], -1) @@ -140,7 +143,7 @@ def runFiducialXS(): years_bis.append('Full') for year in years_bis: if not os.path.exists('../inputs/inputs_sig_'+obsName+'_'+year+'_ORIG.py'): - cmd = 'python addConstrainedModel.py -l -q -b --obsName="'+obsName+'" --obsBins="'+opt.OBSBINS+'" --year="'+year+'"' + cmd = 'python addConstrainedModel.py -l -q -b --obsName="'+obsName+'" --year="'+year+'"' if doubleDiff: cmd += ' --doubleDiff' print cmd output = processCmd(cmd) @@ -158,9 +161,12 @@ def runFiducialXS(): acc = _temp.acc DataModelName = 'SM_125' - if obsName == 'mass4l': PhysicalModels = ['v2','v3'] - elif obsName == 'D0m': PhysicalModels = ['v3','v4'] - else: PhysicalModels = ['v3'] + if obsName.startswith("mass4l"): + PhysicalModels = ['v2','v3'] + elif obsName == 'D0m' or obsName == 'Dcp' or obsName == 'D0hp' or obsName == 'Dint' or obsName == 'DL1' or obsName == 'DL1Zg' or obsName == 'costhetaZ1' or obsName == 'costhetaZ2'or obsName == 'costhetastar' or obsName == 'phi' or obsName == 'phistar' or obsName == 'massZ1' or obsName == 'massZ2': + PhysicalModels = ['v3','v4'] + else: + PhysicalModels = ['v3'] for physicalModel in PhysicalModels: produceDatacards(obsName, observableBins, DataModelName, physicalModel) @@ -204,8 +210,12 @@ def runFiducialXS(): print cmd, '\n' processCmd(cmd,1) cmds.append(cmd) - cmd = 'echo "nuis group = CMS_eff_e CMS_eff_m CMS_hzz2e2mu_Zjets_2016 CMS_hzz2e2mu_Zjets_2017 CMS_hzz2e2mu_Zjets_2018 CMS_hzz4e_Zjets_2016 CMS_hzz4e_Zjets_2017 CMS_hzz4e_Zjets_2018 CMS_hzz4mu_Zjets_2016 CMS_hzz4mu_Zjets_2017 CMS_hzz4mu_Zjets_2018 QCDscale_VV QCDscale_ggVV kfactor_ggzz lumi_13TeV_2016_uncorrelated lumi_13TeV_2017_uncorrelated lumi_13TeV_2018_uncorrelated lumi_13TeV_correlated_16_17_18 lumi_13TeV_correlated_17_18 norm_fakeH pdf_gg pdf_qqbar CMS_zz4l_sigma_e_sig_2017 CMS_zz4l_sigma_e_sig_2016 CMS_zz4l_sigma_m_sig_2018 CMS_zz4l_sigma_m_sig_2017 CMS_zz4l_sigma_m_sig_2016 CMS_zz4l_n_sig_3_2016 CMS_zz4l_n_sig_3_2017 CMS_zz4l_mean_e_sig_2016 CMS_zz4l_mean_e_sig_2017 CMS_zz4l_n_sig_3_2018 CMS_zz4l_mean_m_sig_2018 CMS_zz4l_mean_m_sig_2016 CMS_zz4l_mean_m_sig_2017 CMS_zz4l_sigma_e_sig_2018 CMS_zz4l_mean_e_sig_2018' - if obsName == 'pTj1': cmd += ' CMS_scale_j_Abs CMS_scale_j_Abs_2016 CMS_scale_j_BBEC1 CMS_scale_j_BBEC1_2016 CMS_scale_j_EC2 CMS_scale_j_EC2_2016 CMS_scale_j_FlavQCD CMS_scale_j_HF CMS_scale_j_HF_2016 CMS_scale_j_RelBal CMS_scale_j_RelSample_2016 CMS_scale_j_Abs CMS_scale_j_Abs_2017 CMS_scale_j_BBEC1 CMS_scale_j_BBEC1_2017 CMS_scale_j_EC2 CMS_scale_j_EC2_2017 CMS_scale_j_FlavQCD CMS_scale_j_HF CMS_scale_j_HF_2017 CMS_scale_j_RelBal CMS_scale_j_RelSample_2017 CMS_scale_j_Abs CMS_scale_j_Abs_2018 CMS_scale_j_BBEC1 CMS_scale_j_BBEC1_2018 CMS_scale_j_EC2 CMS_scale_j_EC2_2018 CMS_scale_j_FlavQCD CMS_scale_j_HF CMS_scale_j_HF_2018 CMS_scale_j_RelBal CMS_scale_j_RelSample_2018' + if obsName == 'mass4l_zzfloating': # Remove bkg theo nuisances in case of zz floating + cmd = 'echo "nuis group = CMS_eff_e CMS_eff_m CMS_hzz2e2mu_Zjets_2016 CMS_hzz2e2mu_Zjets_2017 CMS_hzz2e2mu_Zjets_2018 CMS_hzz4e_Zjets_2016 CMS_hzz4e_Zjets_2017 CMS_hzz4e_Zjets_2018 CMS_hzz4mu_Zjets_2016 CMS_hzz4mu_Zjets_2017 CMS_hzz4mu_Zjets_2018 lumi_13TeV_2016_uncorrelated lumi_13TeV_2017_uncorrelated lumi_13TeV_2018_uncorrelated lumi_13TeV_correlated_16_17_18 lumi_13TeV_correlated_17_18 norm_fakeH CMS_zz4l_sigma_e_sig_2017 CMS_zz4l_sigma_e_sig_2016 CMS_zz4l_sigma_m_sig_2018 CMS_zz4l_sigma_m_sig_2017 CMS_zz4l_sigma_m_sig_2016 CMS_zz4l_n_sig_3_2016 CMS_zz4l_n_sig_3_2017 CMS_zz4l_mean_e_sig_2016 CMS_zz4l_mean_e_sig_2017 CMS_zz4l_n_sig_3_2018 CMS_zz4l_mean_m_sig_2018 CMS_zz4l_mean_m_sig_2016 CMS_zz4l_mean_m_sig_2017 CMS_zz4l_sigma_e_sig_2018 CMS_zz4l_mean_e_sig_2018' + else: + cmd = 'echo "nuis group = CMS_eff_e CMS_eff_m CMS_hzz2e2mu_Zjets_2016 CMS_hzz2e2mu_Zjets_2017 CMS_hzz2e2mu_Zjets_2018 CMS_hzz4e_Zjets_2016 CMS_hzz4e_Zjets_2017 CMS_hzz4e_Zjets_2018 CMS_hzz4mu_Zjets_2016 CMS_hzz4mu_Zjets_2017 CMS_hzz4mu_Zjets_2018 QCDscale_VV QCDscale_ggVV kfactor_ggzz lumi_13TeV_2016_uncorrelated lumi_13TeV_2017_uncorrelated lumi_13TeV_2018_uncorrelated lumi_13TeV_correlated_16_17_18 lumi_13TeV_correlated_17_18 norm_fakeH pdf_gg pdf_qqbar CMS_zz4l_sigma_e_sig_2017 CMS_zz4l_sigma_e_sig_2016 CMS_zz4l_sigma_m_sig_2018 CMS_zz4l_sigma_m_sig_2017 CMS_zz4l_sigma_m_sig_2016 CMS_zz4l_n_sig_3_2016 CMS_zz4l_n_sig_3_2017 CMS_zz4l_mean_e_sig_2016 CMS_zz4l_mean_e_sig_2017 CMS_zz4l_n_sig_3_2018 CMS_zz4l_mean_m_sig_2018 CMS_zz4l_mean_m_sig_2016 CMS_zz4l_mean_m_sig_2017 CMS_zz4l_sigma_e_sig_2018 CMS_zz4l_mean_e_sig_2018' + if JES: + cmd += ' CMS_scale_j_Abs CMS_scale_j_Abs_2016 CMS_scale_j_BBEC1 CMS_scale_j_BBEC1_2016 CMS_scale_j_EC2 CMS_scale_j_EC2_2016 CMS_scale_j_FlavQCD CMS_scale_j_HF CMS_scale_j_HF_2016 CMS_scale_j_RelBal CMS_scale_j_RelSample_2016 CMS_scale_j_Abs CMS_scale_j_Abs_2017 CMS_scale_j_BBEC1 CMS_scale_j_BBEC1_2017 CMS_scale_j_EC2 CMS_scale_j_EC2_2017 CMS_scale_j_FlavQCD CMS_scale_j_HF CMS_scale_j_HF_2017 CMS_scale_j_RelBal CMS_scale_j_RelSample_2017 CMS_scale_j_Abs CMS_scale_j_Abs_2018 CMS_scale_j_BBEC1 CMS_scale_j_BBEC1_2018 CMS_scale_j_EC2 CMS_scale_j_EC2_2018 CMS_scale_j_FlavQCD CMS_scale_j_HF CMS_scale_j_HF_2018 CMS_scale_j_RelBal CMS_scale_j_RelSample_2018 CMS_scale_j_ZX' cmd += '" >> hzz4l_all_13TeV_xs_'+obsName+'_bin_'+physicalModel+'.txt' print cmd, '\n' processCmd(cmd,1) @@ -219,8 +229,12 @@ def runFiducialXS(): print cmd, '\n' processCmd(cmd,1) cmds.append(cmd) - cmd = 'echo "nuis group = CMS_eff_e CMS_eff_m CMS_hzz2e2mu_Zjets_'+str(opt.YEAR)+' CMS_hzz4e_Zjets_'+str(opt.YEAR)+' CMS_hzz4mu_Zjets_'+str(opt.YEAR)+' QCDscale_VV QCDscale_ggVV kfactor_ggzz lumi_13TeV_'+str(opt.YEAR)+' norm_fakeH pdf_gg pdf_qqbar CMS_zz4l_sigma_e_sig_'+str(opt.YEAR)+' CMS_zz4l_sigma_m_sig_'+str(opt.YEAR)+' CMS_zz4l_n_sig_3_'+str(opt.YEAR)+' CMS_zz4l_mean_e_sig_'+str(opt.YEAR)+' CMS_zz4l_mean_m_sig_'+str(opt.YEAR)+' CMS_zz4l_sigma_e_sig_'+str(opt.YEAR) - if obsName == 'pTj1': cmd += ' CMS_scale_j_Abs CMS_scale_j_Abs_'+str(opt.YEAR)+' CMS_scale_j_BBEC1 CMS_scale_j_BBEC1_'+str(opt.YEAR)+' CMS_scale_j_EC2 CMS_scale_j_EC2_'+str(opt.YEAR)+' CMS_scale_j_FlavQCD CMS_scale_j_HF CMS_scale_j_HF_'+str(opt.YEAR)+' CMS_scale_j_RelBal CMS_scale_j_RelSample_'+str(opt.YEAR) + if obsName == 'mass4l_zzfloating': + cmd = 'echo "nuis group = CMS_eff_e CMS_eff_m CMS_hzz2e2mu_Zjets_'+str(opt.YEAR)+' CMS_hzz4e_Zjets_'+str(opt.YEAR)+' CMS_hzz4mu_Zjets_'+str(opt.YEAR)+' lumi_13TeV_'+str(opt.YEAR)+' norm_fakeH CMS_zz4l_sigma_e_sig_'+str(opt.YEAR)+' CMS_zz4l_sigma_m_sig_'+str(opt.YEAR)+' CMS_zz4l_n_sig_3_'+str(opt.YEAR)+' CMS_zz4l_mean_e_sig_'+str(opt.YEAR)+' CMS_zz4l_mean_m_sig_'+str(opt.YEAR)+' CMS_zz4l_sigma_e_sig_'+str(opt.YEAR) + else: + cmd = 'echo "nuis group = CMS_eff_e CMS_eff_m CMS_hzz2e2mu_Zjets_'+str(opt.YEAR)+' CMS_hzz4e_Zjets_'+str(opt.YEAR)+' CMS_hzz4mu_Zjets_'+str(opt.YEAR)+' QCDscale_VV QCDscale_ggVV kfactor_ggzz lumi_13TeV_'+str(opt.YEAR)+' norm_fakeH pdf_gg pdf_qqbar CMS_zz4l_sigma_e_sig_'+str(opt.YEAR)+' CMS_zz4l_sigma_m_sig_'+str(opt.YEAR)+' CMS_zz4l_n_sig_3_'+str(opt.YEAR)+' CMS_zz4l_mean_e_sig_'+str(opt.YEAR)+' CMS_zz4l_mean_m_sig_'+str(opt.YEAR)+' CMS_zz4l_sigma_e_sig_'+str(opt.YEAR) + if JES: + cmd += ' CMS_scale_j_Abs CMS_scale_j_Abs_'+str(opt.YEAR)+' CMS_scale_j_BBEC1 CMS_scale_j_BBEC1_'+str(opt.YEAR)+' CMS_scale_j_EC2 CMS_scale_j_EC2_'+str(opt.YEAR)+' CMS_scale_j_FlavQCD CMS_scale_j_HF CMS_scale_j_HF_'+str(opt.YEAR)+' CMS_scale_j_RelBal CMS_scale_j_RelSample_'+str(opt.YEAR)+' CMS_scale_j_ZX' cmd += '" >> hzz4l_all_13TeV_xs_'+obsName+'_bin_'+physicalModel+'.txt' processCmd(cmd,1) cmds.append(cmd) @@ -256,7 +270,7 @@ def runFiducialXS(): # nBins = len(observableBins) if physicalModel == 'v2': # In this case implemented for mass4l only for channel in ['4e', '4mu', '2e2mu']: - cmd = 'combine -n _'+obsName+'_r'+channel+'Bin0 -M MultiDimFit SM_125_all_13TeV_xs_'+obsName+'_bin_v2.root -m 125.38 --freezeParameters MH -P r'+channel+'Bin0 --floatOtherPOIs=1 --saveWorkspace --setParameterRanges r'+channel+'Bin0=0.0,2.5 --redefineSignalPOI r'+channel+'Bin0 --algo=grid --points=100 --cminDefaultMinimizerStrategy 0' + cmd = 'combine -n _'+obsName+'_r'+channel+'Bin0 -M MultiDimFit SM_125_all_13TeV_xs_'+obsName+'_bin_v2.root -m 125.38 --freezeParameters MH -P r'+channel+'Bin0 --floatOtherPOIs=1 --saveWorkspace --setParameterRanges r'+channel+'Bin0=0.0,2.5 --redefineSignalPOI r'+channel+'Bin0 --algo=grid --points=100 --cminDefaultMinimizerStrategy 0 --saveInactivePOI=1' fidxs = 0 fidxs = higgs_xs['ggH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc['ggH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] @@ -284,7 +298,7 @@ def runFiducialXS(): if physicalModel == 'v4': for obsBin in range(nBins): # ----- 2e2mu ----- - cmd = 'combine -n _'+obsName+'_r2e2muBin'+str(obsBin)+' -M MultiDimFit SM_125_all_13TeV_xs_'+obsName+'_bin_v4.root -m 125.38 --freezeParameters MH -P r2e2muBin'+str(obsBin)+' --floatOtherPOIs=1 --saveWorkspace --setParameterRanges r2e2muBin'+str(obsBin)+'=0.0,2.5 --redefineSignalPOI r2e2muBin'+str(obsBin)+' --algo=grid --points=100 --cminDefaultMinimizerStrategy 0' + cmd = 'combine -n _'+obsName+'_r2e2muBin'+str(obsBin)+' -M MultiDimFit SM_125_all_13TeV_xs_'+obsName+'_bin_v4.root -m 125.38 --freezeParameters MH -P r2e2muBin'+str(obsBin)+' --floatOtherPOIs=1 --saveWorkspace --setParameterRanges r2e2muBin'+str(obsBin)+'=0.0,2.5 --redefineSignalPOI r2e2muBin'+str(obsBin)+' --algo=grid --points=100 --cminDefaultMinimizerStrategy 0 --saveInactivePOI=1' fidxs = 0 fidxs = higgs_xs['ggH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_2e2mu']*acc['ggH125_2e2mu_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] @@ -399,7 +413,7 @@ def runFiducialXS(): XH[obsBin]+=XH_fs _obsxsec = XH[obsBin] - if obsName=='mass4l': max_range = '5.0' + if obsName.startswith("mass4l"): max_range = '5.0' else: max_range = '2.5' ## The inclusive xsec for 2j phase space is about 2.49 fb, hence enlarge fit range if ('jj' in obsName) and (obsBin == 0): max_range = '5.0' @@ -446,11 +460,23 @@ def runFiducialXS(): # ----------------- Main ----------------- _fit_dir = os.getcwd() cmds = [] #List of all cmds +global doubleDiff +if 'vs' in opt.OBSNAME: + obsName_tmp = opt.OBSNAME.split(' vs ') + obsName = obsName_tmp[0]+'_'+obsName_tmp[1] + doubleDiff = True +else: + obsName = opt.OBSNAME + doubleDiff = False +if (('pTj1' in obsName) | ('pTHj' in obsName) | ('mHj' in obsName) | ('pTj2' in obsName) | ('mjj' in obsName) | ('absdetajj' in obsName) | ('dphijj' in obsName) | ('pTHjj' in obsName) | ('TCjmax' in obsName) | ('TBjmax' in obsName) | ('njets_pt30_eta4p7' in obsName)): + JES = True +else: + JES = False runFiducialXS() os.chdir(_fit_dir) -if (os.path.exists('commands_'+opt.OBSNAME+'.py')): - os.system('rm commands_'+opt.OBSNAME+'.py') -with open('commands_'+opt.OBSNAME+'.py', 'w') as f: +if (os.path.exists('commands_'+obsName+'.py')): + os.system('rm commands_'+obsName+'.py') +with open('commands_'+obsName+'.py', 'w') as f: for i in cmds: f.write(str(i)+' \n') f.write('\n') diff --git a/fit/addConstrainedModel.py b/fit/addConstrainedModel.py index abfe83d..df5fbd3 100644 --- a/fit/addConstrainedModel.py +++ b/fit/addConstrainedModel.py @@ -42,11 +42,6 @@ def parseOptions(): sys.path.append('../inputs') obsName = opt.OBSNAME -# observableBins = opt.OBSBINS -# observableBins = observableBins.split('|') -# observableBins.pop() -# observableBins.pop(0) - _temp = __import__('inputs_sig_'+obsName+'_'+opt.YEAR, globals(), locals(), ['observableBins','acc','eff','err_eff','outinratio','err_outinratio','inc_wrongfrac','binfrac_wrongfrac','number_fake','lambdajesup','lambdajesdn'], -1) observableBins = _temp.observableBins if not opt.DOUBLEDIFF: lenObsBins = len(observableBins)-1 @@ -292,3 +287,5 @@ def parseOptions(): f.write('number_fake = '+str(number_fake)+' \n') f.write('lambdajesup = '+str(lambdajesup)+' \n') f.write('lambdajesdn = '+str(lambdajesdn)) + +sys.path.remove('../inputs') diff --git a/fit/createDatacard.py b/fit/createDatacard.py index bd7af59..2376da4 100644 --- a/fit/createDatacard.py +++ b/fit/createDatacard.py @@ -9,21 +9,32 @@ def createDatacard(obsName, channel, nBins, obsBin, observableBins, physicalMode if(channel == '2e2mu'): channelNumber = 3 binName = 'a'+str(channelNumber)+'_recobin'+str(obsBin) + # ZZfloating + if 'zzfloating' in obsName: zzfloating = True + else: zzfloating = False + # Root of the name of the process (signal from genBin) processName = 'trueH'+channel+'Bin' - # Background expectations in [105,160] + # Background expectations sys.path.append('../inputs') _temp = __import__('inputs_bkgTemplate_'+obsName, globals(), locals(), ['expected_yield'], -1) expected_yield = _temp.expected_yield + _temp = __import__('inputs_bkg_'+obsName+'_'+year, globals(), locals(), ['fractionsBackground'], -1) + fractionsBackground = _temp.fractionsBackground if jes: + # sys.path.append('../coefficients/JES') + # jesNames = ['Abs', 'Abs_year', 'BBEC1', 'BBEC1_year', 'EC2', 'EC2_year', 'FlavQCD', 'HF', 'HF_year', 'RelBal', 'RelSample_year'] + # jesNames_datacard = [j.replace('year',year) for j in jesNames] # The name of the nuisance in the datacard should have the correspoding year + # _temp = __import__('JESNP_'+obsName+'_'+str(year), globals(), locals(), ['JESNP'], -1) + # jesnp = _temp.JESNP + # sys.path.remove('../coefficients/JES') sys.path.append('../coefficients/JES') jesNames = ['Abs', 'Abs_year', 'BBEC1', 'BBEC1_year', 'EC2', 'EC2_year', 'FlavQCD', 'HF', 'HF_year', 'RelBal', 'RelSample_year'] jesNames_datacard = [j.replace('year',year) for j in jesNames] # The name of the nuisance in the datacard should have the correspoding year - _temp = __import__('JESNP_'+obsName+'_'+str(year), globals(), locals(), ['JESNP'], -1) + _temp = __import__('JESNP_'+obsName, globals(), locals(), ['JESNP'], -1) jesnp = _temp.JESNP sys.path.remove('../coefficients/JES') - # print(jesnp) sys.path.remove('../inputs') #Hard coded values for bkgs @@ -145,10 +156,16 @@ def createDatacard(obsName, channel, nBins, obsBin, observableBins, physicalMode file.write('rate ') for i in range(nBins+2): # In addition to the observableBins, there are out_trueH, fakeH file.write('1.0 ') - # file.write(str(bkg_qqzz[year+'_'+channel])+' '+str(bkg_ggzz[year+'_'+channel])+' '+str(bkg_zx[year+'_'+channel])+'\n') #Old implementation with hard coding bkg expectation values - file.write(str(expected_yield[int(year),'qqzz',channel])+' '+str(expected_yield[int(year),'ggzz',channel])+' '+str(expected_yield[int(year),'ZX',channel])+'\n') + if zzfloating: + file.write('1 1 '+str(expected_yield[int(year),'ZX',channel])+'\n') + else: + file.write(str(expected_yield[int(year),'qqzz',channel])+' '+str(expected_yield[int(year),'ggzz',channel])+' '+str(expected_yield[int(year),'ZX',channel])+'\n') file.write('------------ \n') + if zzfloating: + # rateParam qqZZ floating + file.write('zz_norm_'+str(obsBin)+' rateParam '+binName+' bkg_*zz '+str(expected_yield['ZZ_'+str(obsBin)])+' ['+str(expected_yield['ZZ_'+str(obsBin)]-100)+','+str(expected_yield['ZZ_'+str(obsBin)]+100)+']\n') + # norm_fake file.write('norm_fakeH lnU ') for i in range(nBins+1): # Signal + out_trueH @@ -156,28 +173,53 @@ def createDatacard(obsName, channel, nBins, obsBin, observableBins, physicalMode file.write('10.0 - - - # [/10,*10]\n') if yearSetting == 'Full': - # lumi_uncorrelated - file.write('lumi_13TeV_'+year+'_uncorrelated lnN ') - for i in range(nBins+4): # All except ZX - file.write(lumi[year]+' ') - file.write('-\n') # ZX - # lumi_correlated_16_17_18 - file.write('lumi_13TeV_correlated_16_17_18 lnN ') - for i in range(nBins+4): # All except ZX - file.write(lumi_corr_16_17_18[year]+' ') - file.write('-\n') # ZX - # lumi_correlated_17_18 - if year == '2017' or year == '2018': - file.write('lumi_13TeV_correlated_17_18 lnN ') + if zzfloating: + # lumi_uncorrelated + file.write('lumi_13TeV_'+year+'_uncorrelated lnN ') + for i in range(nBins+2): # signals + out + fake + file.write(lumi[year]+' ') + file.write('- - -\n') # qqzz + ggzz + ZX + # lumi_correlated_16_17_18 + file.write('lumi_13TeV_correlated_16_17_18 lnN ') + for i in range(nBins+2): # signals + out + fake + file.write(lumi_corr_16_17_18[year]+' ') + file.write('- - -\n') # qqzz + ggzz + ZX + # lumi_correlated_17_18 + if year == '2017' or year == '2018': + file.write('lumi_13TeV_correlated_17_18 lnN ') + for i in range(nBins+2): # signals + out + fake + file.write(lumi_corr_17_18[year]+' ') + file.write('- - -\n') # qqzz + ggzz + ZX + else: + # lumi_uncorrelated + file.write('lumi_13TeV_'+year+'_uncorrelated lnN ') for i in range(nBins+4): # All except ZX - file.write(lumi_corr_17_18[year]+' ') + file.write(lumi[year]+' ') file.write('-\n') # ZX + # lumi_correlated_16_17_18 + file.write('lumi_13TeV_correlated_16_17_18 lnN ') + for i in range(nBins+4): # All except ZX + file.write(lumi_corr_16_17_18[year]+' ') + file.write('-\n') # ZX + # lumi_correlated_17_18 + if year == '2017' or year == '2018': + file.write('lumi_13TeV_correlated_17_18 lnN ') + for i in range(nBins+4): # All except ZX + file.write(lumi_corr_17_18[year]+' ') + file.write('-\n') # ZX else: - # lumi - file.write('lumi_13TeV_'+year+' lnN ') - for i in range(nBins+4): # All except ZX - file.write(lumi[year]+' ') - file.write('-\n') # ZX + if zzfloating: + # lumi + file.write('lumi_13TeV_'+year+' lnN ') + for i in range(nBins+2): # signals + out + fake + file.write(lumi[year]+' ') + file.write('- - -\n') # qqzz + ggzz + ZX + else: + # lumi + file.write('lumi_13TeV_'+year+' lnN ') + for i in range(nBins+4): # All except ZX + file.write(lumi[year]+' ') + file.write('-\n') # ZX # Lepton efficiency if channel == '4mu' or channel == '2e2mu': @@ -208,26 +250,27 @@ def createDatacard(obsName, channel, nBins, obsBin, observableBins, physicalMode file.write('CMS_zz4l_n_sig_'+str(channelNumber)+'_'+year+' param 0.0 0.05\n') # Theoretical - file.write('QCDscale_ggVV lnN ') - for i in range(nBins+3): # Signal + out + fake + qqzz - file.write('- ') - file.write('1.039/0.961 -\n') - file.write('QCDscale_VV lnN ') - for i in range(nBins+2): # Signal + out + fake - file.write('- ') - file.write('1.0325/0.958 - -\n') - file.write('pdf_gg lnN ') - for i in range(nBins+3): # Signal + out + fake + qqzz - file.write('- ') - file.write('1.032/0.968 -\n') - file.write('pdf_qqbar lnN ') - for i in range(nBins+2): # Signal + out + fake - file.write('- ') - file.write('1.031/0.966 - -\n') - file.write('kfactor_ggzz lnN ') - for i in range(nBins+3): # Signal + out + fake + bkg_qqzz - file.write('- ') - file.write('1.1 -\n') + if not zzfloating: + file.write('QCDscale_ggVV lnN ') + for i in range(nBins+3): # Signal + out + fake + qqzz + file.write('- ') + file.write('1.039/0.961 -\n') + file.write('QCDscale_VV lnN ') + for i in range(nBins+2): # Signal + out + fake + file.write('- ') + file.write('1.0325/0.958 - -\n') + file.write('pdf_gg lnN ') + for i in range(nBins+3): # Signal + out + fake + qqzz + file.write('- ') + file.write('1.032/0.968 -\n') + file.write('pdf_qqbar lnN ') + for i in range(nBins+2): # Signal + out + fake + file.write('- ') + file.write('1.031/0.966 - -\n') + file.write('kfactor_ggzz lnN ') + for i in range(nBins+3): # Signal + out + fake + bkg_qqzz + file.write('- ') + file.write('1.1 -\n') # # ZX # file.write('CMS_zjets_bkgdcompo_'+str(year)+' lnN ') @@ -239,19 +282,24 @@ def createDatacard(obsName, channel, nBins, obsBin, observableBins, physicalMode if jes == True: for index,jesName in enumerate(jesNames_datacard): file.write('CMS_scale_j_'+jesName+' lnN ') - for i in range(nBins): # Signals - file.write(str(jesnp['fiducial_'+jesNames[index]+'_'+channel+'_'+obsName+'_genbin'+str(i)+'_recobin'+str(obsBin)])+' ') - file.write(str(jesnp['nonFiducial_'+jesNames[index]+'_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])+' ') - file.write(str(jesnp['nonResonant_'+jesNames[index]+'_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])+' ') - file.write(str(jesnp['qqzz_'+jesNames[index]+'_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])+' ') - file.write(str(jesnp['ggzz_'+jesNames[index]+'_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])+' ') + + # for i in range(nBins): # Signals + # file.write(str(jesnp['fiducial_'+jesNames[index]+'_'+channel+'_'+obsName+'_genbin'+str(i)+'_recobin'+str(obsBin)])+' ') + # file.write(str(jesnp['nonFiducial_'+jesNames[index]+'_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])+' ') + # file.write(str(jesnp['nonResonant_'+jesNames[index]+'_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])+' ') + + for i in range(nBins+2): # Signal + out + fake + file.write(str(jesnp['signal_'+jesNames[index]+'_'+channel+'_'+str(year)+'_'+obsName+'_recobin'+str(obsBin)])+' ') + + # Bkgs + file.write(str(jesnp['qqzz_'+jesNames[index]+'_'+channel+'_'+str(year)+'_'+obsName+'_recobin'+str(obsBin)])+' ') + file.write(str(jesnp['ggzz_'+jesNames[index]+'_'+channel+'_'+str(year)+'_'+obsName+'_recobin'+str(obsBin)])+' ') file.write('-\n') # ZX #file.write('JES param 0.0 1.0\n') file.write('CMS_scale_j_ZX lnN ') for i in range(nBins+4): # All except ZX file.write('- ') - file.write(str(jesnp['ZX_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])+'\n') - + file.write(str(jesnp['ZX_'+channel+'_'+str(year)+'_'+obsName+'_recobin'+str(obsBin)])+'\n') file.close() diff --git a/fit/createXSworkspace.py b/fit/createXSworkspace.py index 7713ec6..fa3128f 100644 --- a/fit/createXSworkspace.py +++ b/fit/createXSworkspace.py @@ -5,6 +5,47 @@ import os,sys,subprocess from math import trunc +from paths import path + +# Considering or not decimals in bin boundaries +decimal = { +'mass4l': False, +'mass4l_zzfloating': False, +'njets_pt30_eta4p7': False, +'pT4l': False, +'rapidity4l': True, +'costhetaZ1': True, +'costhetaZ2': True, +'phi': True, +'phistar': True, +'costhetastar': True, +'massZ1': False, +'massZ2': False, +'pTj1': False, +'pTHj': False, +'mHj': False, +'pTj2': False, +'mjj': False, +'absdetajj': True, +'dphijj': True, +'pTHjj': False, +'TCjmax': False, +'TBjmax': False, +'D0m': True, +'Dcp': True, +'D0hp': True, +'Dint': True, +'DL1': True, +'DL1Zg': True, +'rapidity4l_pT4l': True, +'njets_pt30_eta4p7 vs pT4l': False, +'pTj1_pTj2': False, +'pT4l_pTHj': False, +'massZ1_massZ2': False, +'TCjmax_pT4l': False +} + + sys.path.append('../../inputs/') sys.path.append('../../templates/') @@ -441,11 +482,15 @@ def createXSworkspace(obsName, channel, nBins, obsBin, observableBins, usecfacto os.chdir('../../templates/'+year+"/"+obsName+"/") - if doubleDiff: + if doubleDiff and decimal[obsName]: + template_qqzzName = "XSBackground_qqzz_"+channel+"_"+obsName+"_"+str(obsBin_low)+"_"+str(obsBin_high)+"_"+str(obsBin_2nd_low)+"_"+str(obsBin_2nd_high)+".root" + template_ggzzName = "XSBackground_ggzz_"+channel+"_"+obsName+"_"+str(obsBin_low)+"_"+str(obsBin_high)+"_"+str(obsBin_2nd_low)+"_"+str(obsBin_2nd_high)+".root" + template_zjetsName = "XSBackground_ZJetsCR_"+channel+"_"+obsName+"_"+str(obsBin_low)+"_"+str(obsBin_high)+"_"+str(obsBin_2nd_low)+"_"+str(obsBin_2nd_high)+".root" + elif doubleDiff: template_qqzzName = "XSBackground_qqzz_"+channel+"_"+obsName+"_"+str(trunc(obsBin_low))+"_"+str(trunc(obsBin_high))+"_"+str(trunc(obsBin_2nd_low))+"_"+str(trunc(obsBin_2nd_high))+".root" template_ggzzName = "XSBackground_ggzz_"+channel+"_"+obsName+"_"+str(trunc(obsBin_low))+"_"+str(trunc(obsBin_high))+"_"+str(trunc(obsBin_2nd_low))+"_"+str(trunc(obsBin_2nd_high))+".root" template_zjetsName = "XSBackground_ZJetsCR_"+channel+"_"+obsName+"_"+str(trunc(obsBin_low))+"_"+str(trunc(obsBin_high))+"_"+str(trunc(obsBin_2nd_low))+"_"+str(trunc(obsBin_2nd_high))+".root" - elif obsName=='Dcp' or obsName=='Dint' or obsName=='D0m' or obsName=='rapidity4l': + elif decimal[obsName]: template_qqzzName = "XSBackground_qqzz_"+channel+"_"+obsName+"_"+str(obsBin_low)+"_"+str(obsBin_high)+".root" template_ggzzName = "XSBackground_ggzz_"+channel+"_"+obsName+"_"+str(obsBin_low)+"_"+str(obsBin_high)+".root" template_zjetsName = "XSBackground_ZJetsCR_"+channel+"_"+obsName+"_"+str(obsBin_low)+"_"+str(obsBin_high)+".root" @@ -459,7 +504,8 @@ def createXSworkspace(obsName, channel, nBins, obsBin, observableBins, usecfacto # template_zjetsName = "/eos/user/a/atarabin/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXS/templates/"+year+"/"+obsName+"/XSBackground_ZJetsCR_"+channel+"_"+obsName+"_"+obsBin_low+"_"+obsBin_high+".root" qqzzTempFile = ROOT.TFile(template_qqzzName,"READ") - if obsName=='Dcp' or obsName=='Dint' or obsName=='D0m' or obsName=='rapidity4l': qqzzTemplate = qqzzTempFile.Get("m4l_"+obsName+"_"+str(obsBin_low)+"_"+str(obsBin_high)) + if decimal[obsName] and doubleDiff: qqzzTemplate = qqzzTempFile.Get("m4l_"+obsName+"_"+str(obsBin_low)+"_"+str(obsBin_high)+"_"+str(obsBin_2nd_low)+"_"+str(obsBin_2nd_high)) + elif decimal[obsName]: qqzzTemplate = qqzzTempFile.Get("m4l_"+obsName+"_"+str(obsBin_low)+"_"+str(obsBin_high)) elif not doubleDiff: qqzzTemplate = qqzzTempFile.Get("m4l_"+obsName+"_"+str(trunc(obsBin_low))+"_"+str(trunc(obsBin_high))) elif doubleDiff: qqzzTemplate = qqzzTempFile.Get("m4l_"+obsName+"_"+str(trunc(obsBin_low))+"_"+str(trunc(obsBin_high))+"_"+str(trunc(obsBin_2nd_low))+"_"+str(trunc(obsBin_2nd_high))) print qqzzTempFile @@ -467,13 +513,15 @@ def createXSworkspace(obsName, channel, nBins, obsBin, observableBins, usecfacto print 'qqZZ bins',qqzzTemplate.GetNbinsX(),qqzzTemplate.GetBinLowEdge(1),qqzzTemplate.GetBinLowEdge(qqzzTemplate.GetNbinsX()+1) ggzzTempFile = ROOT.TFile(template_ggzzName,"READ") - if obsName=='Dcp' or obsName=='Dint' or obsName=='D0m' or obsName=="rapidity4l": ggzzTemplate = ggzzTempFile.Get("m4l_"+obsName+"_"+str(obsBin_low)+"_"+str(obsBin_high)) + if decimal[obsName] and doubleDiff: ggzzTemplate = ggzzTempFile.Get("m4l_"+obsName+"_"+str(obsBin_low)+"_"+str(obsBin_high)+"_"+str(obsBin_2nd_low)+"_"+str(obsBin_2nd_high)) + elif decimal[obsName]: ggzzTemplate = ggzzTempFile.Get("m4l_"+obsName+"_"+str(obsBin_low)+"_"+str(obsBin_high)) elif not doubleDiff: ggzzTemplate = ggzzTempFile.Get("m4l_"+obsName+"_"+str(trunc(obsBin_low))+"_"+str(trunc(obsBin_high))) elif doubleDiff: ggzzTemplate = ggzzTempFile.Get("m4l_"+obsName+"_"+str(trunc(obsBin_low))+"_"+str(trunc(obsBin_high))+"_"+str(trunc(obsBin_2nd_low))+"_"+str(trunc(obsBin_2nd_high))) print 'ggZZ bins',ggzzTemplate.GetNbinsX(),ggzzTemplate.GetBinLowEdge(1),ggzzTemplate.GetBinLowEdge(ggzzTemplate.GetNbinsX()+1) zjetsTempFile = ROOT.TFile(template_zjetsName,"READ") - if obsName=='Dcp' or obsName=='Dint' or obsName=='D0m' or obsName=="rapidity4l": zjetsTemplate = zjetsTempFile.Get("m4l_"+obsName+"_"+str(obsBin_low)+"_"+str(obsBin_high)) + if decimal[obsName] and doubleDiff: zjetsTemplate = zjetsTempFile.Get("m4l_"+obsName+"_"+str(obsBin_low)+"_"+str(obsBin_high)+"_"+str(obsBin_2nd_low)+"_"+str(obsBin_2nd_high)) + elif decimal[obsName]: zjetsTemplate = zjetsTempFile.Get("m4l_"+obsName+"_"+str(obsBin_low)+"_"+str(obsBin_high)) elif not doubleDiff: zjetsTemplate = zjetsTempFile.Get("m4l_"+obsName+"_"+str(trunc(obsBin_low))+"_"+str(trunc(obsBin_high))) elif doubleDiff: zjetsTemplate = zjetsTempFile.Get("m4l_"+obsName+"_"+str(trunc(obsBin_low))+"_"+str(trunc(obsBin_high))+"_"+str(trunc(obsBin_2nd_low))+"_"+str(trunc(obsBin_2nd_high))) print 'zjets bins',zjetsTemplate.GetNbinsX(),zjetsTemplate.GetBinLowEdge(1),zjetsTemplate.GetBinLowEdge(zjetsTemplate.GetNbinsX()+1) @@ -523,7 +571,7 @@ def createXSworkspace(obsName, channel, nBins, obsBin, observableBins, usecfacto # os.system('c++ -o skim_data_tree skim_data_tree.cpp `root-config --cflags --glibs`') # os.system('./skim_data_tree '+year) # os.chdir('/eos/user/a/atarabin/CMSSW_10_2_13/src/HiggsAnalysis/FiducialXS/datacard_'+year) - data_obs_file = ROOT.TFile('/eos/user/a/atarabin/Data/reducedTree_AllData_'+year+'.root') + data_obs_file = ROOT.TFile(path['eos_path']+'Data/reducedTree_AllData_'+year+'.root') data_obs_tree = data_obs_file.Get('SR') print obsName,obsBin_low,obsBin_high diff --git a/fit/impacts.py b/fit/impacts.py index 13a8662..3495d3b 100644 --- a/fit/impacts.py +++ b/fit/impacts.py @@ -41,9 +41,9 @@ def parseOptions(): global opt, args (opt, args) = parser.parse_args() - if (opt.OBSBINS=='' and opt.OBSNAME!='inclusive'): - parser.error('Bin boundaries not specified for differential measurement. Exiting...') - sys.exit() + # if (opt.OBSBINS=='' and opt.OBSNAME!='inclusive'): + # parser.error('Bin boundaries not specified for differential measurement. Exiting...') + # sys.exit() # parse the arguments and options global opt, args, runAllSteps @@ -69,10 +69,11 @@ def processCmd(cmd, quiet = 0): def impactPlots(): - # prepare the set of bin boundaries to run over, only 1 bin in case of the inclusive measurement - observableBins = {0:(opt.OBSBINS.split("|")[1:(len(opt.OBSBINS.split("|"))-1)]),1:['0','inf']}[opt.OBSBINS=='inclusive'] + sys.path.append('../inputs/') + _temp = __import__('inputs_sig_'+obsName+'_'+opt.YEAR, globals(), locals(), ['observableBins'], -1) + observableBins = _temp.observableBins + sys.path.remove('../inputs/') ## Run for the given observable - obsName = opt.OBSNAME print 'NP impacts calculation - '+obsName+' - bin boundaries: ', observableBins, '\n' _temp = __import__('higgs_xsbr_13TeV', globals(), locals(), ['higgs_xs','higgs4l_br'], -1) @@ -88,6 +89,8 @@ def impactPlots(): os.chdir('../impacts/') print 'Current directory: impacts' nBins = len(observableBins) + if '_' in obsName and obsName!='mass4l_zzfloating': nBins = len(observableBins)+1 + #nBins = len(observableBins) tmp_xs = {} tmp_xs_sm = {} xsec = [] @@ -185,8 +188,9 @@ def impactPlots(): cmd_sigma = cmd_sigma[:-1] print(cmd_sigma) - if (obsName == 'mass4l'): max_sigma = '5' - else: max_sigma = '2.5' + if (obsName.startswith("mass4l")): max_sigma = '5' + # else: max_sigma = '2.5' + else: max_sigma = '5' ### First step (Files from asimov and data have the same name) cmd = 'combineTool.py -M Impacts -d ../combine_files/SM_125_all_13TeV_xs_'+obsName+'_bin_'+opt.PHYSICSMODEL+'.root -m 125.38 --cminDefaultMinimizerStrategy 0 --doInitialFit --robustFit 1 --redefineSignalPOIs ' @@ -324,10 +328,15 @@ def impactPlots(): # ----------------- Main ----------------- cmds = [] #List of all cmds +if 'vs' in opt.OBSNAME: + obsName_tmp = opt.OBSNAME.split(' vs ') + obsName = obsName_tmp[0]+'_'+obsName_tmp[1] +else: + obsName = opt.OBSNAME impactPlots() -if (os.path.exists('commands_impacts_'+opt.OBSNAME+'.py')): - os.system('rm commands_impacts_'+opt.OBSNAME+'.py') -with open('commands_impacts_'+opt.OBSNAME+'.py', 'w') as f: +if (os.path.exists('commands_impacts_'+obsName+'_'+opt.PHYSICSMODEL+'.py')): + os.system('rm commands_impacts_'+obsName+'_'+opt.PHYSICSMODEL+'.py') +with open('commands_impacts_'+obsName+'_'+opt.PHYSICSMODEL+'.py', 'w') as f: for i in cmds: f.write(str(i)+' \n') f.write('\n') diff --git a/helperstuff/._binning.py b/helperstuff/._binning.py new file mode 100644 index 0000000..2194d63 Binary files /dev/null and b/helperstuff/._binning.py differ diff --git a/helperstuff/._createdf_jes.py b/helperstuff/._createdf_jes.py new file mode 100644 index 0000000..c76091d Binary files /dev/null and b/helperstuff/._createdf_jes.py differ diff --git a/helperstuff/__init__.py b/helperstuff/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/coefficients/JES/binning.py b/helperstuff/binning.py similarity index 66% rename from coefficients/JES/binning.py rename to helperstuff/binning.py index a4243e8..d9a3861 100644 --- a/coefficients/JES/binning.py +++ b/helperstuff/binning.py @@ -1,9 +1,47 @@ -def binning(obsBins_input): +list = { +'mass4l': '|105|140|', +'mass4l_zzfloating': '|105|160|', +'njets_pt30_eta4p7': '|0|1|2|3|4|14|', +'pT4l': '|0|10|20|30|45|60|80|120|200|3000|', +'rapidity4l': '|0.0|0.15|0.3|0.45|0.6|0.75|0.9|1.2|1.6|2.5|', +'costhetaZ1': '|-1.0|-0.75|-0.50|-0.25|0.0|0.25|0.50|0.75|1.0|', +'costhetaZ2': '|-1.0|-0.75|-0.50|-0.25|0.0|0.25|0.50|0.75|1.0|', +'phi': '|-3.14159265359|-2.35619449019|-1.57079632679|-0.785398163397|0.0|0.785398163397|1.57079632679|2.35619449019|3.14159265359|', +'phistar': '|-3.14159265359|-2.35619449019|-1.57079632679|-0.785398163397|0.0|0.785398163397|1.57079632679|2.35619449019|3.14159265359|', +'costhetastar': '|-1.0|-0.75|-0.50|-0.25|0.0|0.25|0.50|0.75|1.0|', +'massZ1': '|40|65|73|80|85|90|120|', +'massZ2': '|12|22|25|28|30|32|35|40|50|65|', +'pTj1': '|-2|30|55|95|200|1300|', +'pTHj': '|-2|0|30|60|110|1300|', +'mHj': '|-2|110|180|220|300|400|600|3000|', +'pTj2': '|-2|30|40|65|90|1300|', +'mjj': '|-2|0|120|300|1300|', +'absdetajj': '|-100|0|0.7|1.6|3.0|10.0|', +'dphijj': '|-100|-3.14159265359|-1.5707963267948966|0|1.5707963267948966|3.14159265359|', +'pTHjj': '|-2|0|20|40|60|110|1300|', +'TCjmax': '|-2|15|20|30|50|80|1000|', +'TBjmax': '|-2|30|70|130|250|400|1000|', +'D0m': '|0.0|0.4|0.5|0.6|0.7|0.8|0.9|1.0|', +'Dcp': '|-0.75|-0.25|-0.1|0|0.1|0.25|0.75|', +'D0hp': '|0.0|0.35|0.4|0.45|0.55|0.65|0.75|1.0|', +'Dint': '|0.0|0.7|0.8|0.9|0.95|1.0|', +'DL1': '|0.0|0.45|0.5|0.6|0.7|1.0|', +'DL1Zg': '|0.0|0.35|0.45|0.5|0.55|0.65|1.0|', +'rapidity4l vs pT4l': '|0|0.5|1.0|2.5| vs |0|40|80|150|1300| / |0|45|120|1300| / |0|45|120|1300|', +'njets_pt30_eta4p7 vs pT4l': '|0|1|2|20| vs |0|15|30|1300| / |0|60|80|120|1300| / |0|100|170|250|1300|', +'pTj1 vs pTj2': '|-2|30| vs |-2|30| / |30|60| vs |30|60| / |60|350| vs |30|60| / |60|350| vs |60|350|', +'pT4l vs pTHj': '|-2|0| vs |-2|0| / |0|85| vs |0|30| / |85|350| vs |0|45| / |0|85| vs |30|350| / |85|350| vs |45|350|', +'massZ1 vs massZ2': '|40|85| vs |12|35| / |40|70| vs |35|65| / |70|120| vs |35|65| / |85|120| vs |30|35| / |85|120| vs |24|30| / |85|120| vs |12|24|', +'TCjmax vs pT4l': '|0|15|25|40|1300| vs |0|15|30|45|70|120|1300| / |0|120|1300| / |0|120|1300| / |0|200|1300|', +} + +def binning(var): + obsBins_input = list[var] if not 'vs' in obsBins_input: #It is not a double-differential analysis obs_bins = {0:(obsBins_input.split("|")[1:(len(obsBins_input.split("|"))-1)]),1:['0','inf']}[obsBins_input=='inclusive'] obs_bins = [float(i) for i in obs_bins] #Convert a list of str to a list of float doubleDiff = False - print ('It is a single-differential measurement, binning', obs_bins) + print 'It is a single-differential measurement, binning', obs_bins else: #It is a double-differential analysis doubleDiff = True # The structure of obs_bins is: @@ -63,8 +101,8 @@ def binning(obsBins_input): obs_bins[k].append(obs_bins_2nd[j+1]) k +=1 else: - print ('Problem in the definition of the binning') + print 'Problem in the definition of the binning' quit() - print ('It is a double-differential measurement, binning for the 1st variable', obs_bins_1st, 'and for the 2nd variable', obs_bins_2nd) - print (obs_bins) + print 'It is a double-differential measurement, binning for the 1st variable', obs_bins_1st, 'and for the 2nd variable', obs_bins_2nd + print obs_bins return obs_bins, doubleDiff diff --git a/coefficients/JES/createdf_jes.py b/helperstuff/createdf_jes.py similarity index 62% rename from coefficients/JES/createdf_jes.py rename to helperstuff/createdf_jes.py index 93bd82a..92c61df 100644 --- a/coefficients/JES/createdf_jes.py +++ b/helperstuff/createdf_jes.py @@ -1,6 +1,6 @@ import numpy as np import pandas as pd -import uproot +import uproot3 as uproot from math import sqrt, log import sys,os import optparse @@ -24,18 +24,24 @@ def weight(df, xsec, gen, lumi, additional = None): coeff = (lumi * 1000 * xsec) / gen #Reco weight_reco = (df.overallEventWeight * df.L1prefiringWeight) + if additional == 'ggH': + weight_reco *= df.ggH_NNLOPS_weight + elif additional == 'qqzz': + weight_reco *= df.KFactor_EW_qqZZ*df.KFactor_QCD_qqZZ_M + elif additional == 'ggzz': + weight_reco *= df.KFactor_QCD_ggZZ_Nominal weight_histo_reco = weight_reco * coeff #Columns in pandas df['weight_reco'] = weight_reco #Powheg df['weight_histo_reco'] = weight_histo_reco #Powheg - if additional == 'ggH': - weight_reco_NNLOPS = weight_reco * df.ggH_NNLOPS_weight - weight_histo_reco_NNLOPS = weight_histo_reco * df.ggH_NNLOPS_weight - df['weight_reco_NNLOPS'] = weight_reco_NNLOPS #NNLOPS (only ggH) - df['weight_histo_reco_NNLOPS'] = weight_histo_reco_NNLOPS #NNLOPS (only ggH) - else: - df['weight_reco_NNLOPS'] = -1 - df['weight_histo_reco_NNLOPS'] = -1 + # if additional == 'ggH': + # weight_reco_NNLOPS = weight_reco * df.ggH_NNLOPS_weight + # weight_histo_reco_NNLOPS = weight_histo_reco * df.ggH_NNLOPS_weight + # df['weight_reco_NNLOPS'] = weight_reco_NNLOPS #NNLOPS (only ggH) + # df['weight_histo_reco_NNLOPS'] = weight_histo_reco_NNLOPS #NNLOPS (only ggH) + # else: + # df['weight_reco_NNLOPS'] = -1 + # df['weight_histo_reco_NNLOPS'] = -1 return df # Uproot to generate pandas @@ -70,11 +76,27 @@ def prepareTrees(year): def xsecs(year): xsec_sig = {} xsec_bkg = {} - d_sig, d_bkg = prepareTrees(year) - for signal in signals_original: - xsec_sig[signal] = d_sig[signal].pandas.df('xsec').xsec[0] - for bkg in bkgs: - xsec_bkg[bkg] = d_bkg[bkg].pandas.df('xsec').xsec[0] + #Hard-coded values + xsec_sig['ggH125'] = 0.0133352 + xsec_sig['VBFH125'] = 0.0010381 + xsec_sig['ttH125'] = 0.0003639 + xsec_sig['WminusH125'] = 0.0001462 + xsec_sig['WplusH125'] = 0.0002305 + xsec_sig['ZH125'] = 0.0005321 + + xsec_bkg['ZZTo4lext'] = 1.2560000 + xsec_bkg['ggTo2e2mu_Contin_MCFM701'] = 0.0031914 + xsec_bkg['ggTo2e2tau_Contin_MCFM701'] = 0.0031914 + xsec_bkg['ggTo2mu2tau_Contin_MCFM701'] = 0.0031914 + xsec_bkg['ggTo4e_Contin_MCFM701'] = 0.0015854 + xsec_bkg['ggTo4mu_Contin_MCFM701'] = 0.0015854 + xsec_bkg['ggTo4tau_Contin_MCFM701'] = 0.0015854 + + # d_sig, d_bkg = prepareTrees(year) + # for signal in signals_original: + # xsec_sig[signal] = d_sig[signal].pandas.df('xsec').xsec[0] + # for bkg in bkgs: + # xsec_bkg[bkg] = d_bkg[bkg].pandas.df('xsec').xsec[0] return xsec_sig, xsec_bkg @@ -96,61 +118,6 @@ def add_fin_state_reco(i, j): return fin -def add_fin_state_gen(lepId, Hindex, number): - if (Hindex[0]==99) | (Hindex[1]==99) | (Hindex[2]==99) | (Hindex[3]==99): - return 'other' - if (abs(lepId[Hindex[0]])==11) & (abs(lepId[Hindex[2]])==11): - fin = '4e' - elif (abs(lepId[Hindex[0]])==13) & (abs(lepId[Hindex[2]])==13): - fin = '4mu' - elif ((abs(lepId[Hindex[0]])==11) & (abs(lepId[Hindex[2]])==13)) | ((abs(lepId[Hindex[0]])==13) & (abs(lepId[Hindex[2]])==11)): - fin = '2e2mu' - else: - fin = 'other' - return fin - - -def add_fin_state_gen_out(ZdauId,event): - if (abs(ZdauId[0])==11) and (abs(ZdauId[1])==11): - fin = '4e' - elif (abs(ZdauId[0])==13) and (abs(ZdauId[1])==13): - fin = '4mu' - elif ((abs(ZdauId[0])==11) and (abs(ZdauId[1])==13)) or ((abs(ZdauId[0])==13) and (abs(ZdauId[1])==11)): - fin = '2e2mu' - else: - fin = 'other' - return fin - - -def add_fin_state_gen_out_ZH(ZdauId,momId): - if ((abs(ZdauId[0])==11) and (abs(ZdauId[1])==11) and (momId[0]==25) and (momId[1]==25)) or ((abs(ZdauId[0])==11) and (abs(ZdauId[2])==11) and (momId[0]==25) and (momId[2]==25)) or ((abs(ZdauId[1])==11) and (abs(ZdauId[2])==11) and (momId[1]==25) and (momId[2]==25)): - fin = '4e' - elif ((abs(ZdauId[0])==13) and (abs(ZdauId[1])==13) and (momId[0]==25) and (momId[1]==25)) or ((abs(ZdauId[0])==13) and (abs(ZdauId[2])==13)&(momId[0]==25) and (momId[2]==25)) or ((abs(ZdauId[1])==13) and (abs(ZdauId[2])==13) and (momId[1]==25) and (momId[2]==25)): - fin = '4mu' - elif (momId[0]==25 and (ZdauId[0]==11 or ZdauId[0]==13) and momId[1]==25 and (ZdauId[1]==11 or ZdauId[1]==13) and (ZdauId[0]!=ZdauId[1])) or (momId[0]==25 and (ZdauId[0]==11 or ZdauId[0]==13) and momId[2]==25 and (ZdauId[2]==11 or ZdauId[2]==13) and (ZdauId[0]!=ZdauId[2])) or (momId[1]==25 and (ZdauId[1]==11 or ZdauId[1]==13) and momId[2]==25 and (ZdauId[2]==11 or ZdauId[2]==13) and (ZdauId[1]!=ZdauId[2])): - fin = '2e2mu' - else: - fin = 'other' - return fin - - -def add_cuth4l_gen(momMomId,Hindex): - if (Hindex[0]==99) | (Hindex[1]==99) | (Hindex[2]==99) | (Hindex[3]==99): - return False - if momMomId[Hindex[0]]==25 and momMomId[Hindex[1]]==25 and momMomId[Hindex[2]]==25 and momMomId[Hindex[3]]==25: - return True - else: - return False - - -def add_cuth4l_reco(Hindex,genIndex,momMomId,momId): - if (Hindex[0]==99) | (Hindex[1]==99) | (Hindex[2]==99) | (Hindex[3]==99): - return False - if ((genIndex[Hindex[0]]>-0.5)*momMomId[max(0,genIndex[Hindex[0]])]==25) and ((genIndex[Hindex[0]]>-0.5)*momId[max(0,genIndex[Hindex[0]])]==23) and ((genIndex[Hindex[1]]>-0.5)*momMomId[max(0,genIndex[Hindex[1]])]==25) and ((genIndex[Hindex[1]]>-0.5)*momId[max(0,genIndex[Hindex[1]])]==23) and ((genIndex[Hindex[2]]>-0.5)*momMomId[max(0,genIndex[Hindex[2]])]==25) and ((genIndex[Hindex[2]]>-0.5)*momId[max(0,genIndex[Hindex[2]])]==23) and ((genIndex[Hindex[3]]>-0.5)*momMomId[max(0,genIndex[Hindex[3]])]==25) and ((genIndex[Hindex[3]]>-0.5)*momId[max(0,genIndex[Hindex[3]])]==23): - return True - else: - return False - # Get the "number" of MC events to divide the weights def generators(year): gen_sig = {} @@ -167,6 +134,7 @@ def generators(year): input_file = ROOT.TFile(fname) hCounters = input_file.Get("Counters") gen_sig[signal] = hCounters.GetBinContent(40) + input_file.Close() for bkg in bkgs: fname = eos_path_sig + '%i_MELA' %year @@ -179,6 +147,7 @@ def generators(year): input_file = ROOT.TFile(fname) hCounters = input_file.Get("Counters") gen_bkg[bkg] = hCounters.GetBinContent(40) + input_file.Close() return gen_sig, gen_bkg @@ -193,7 +162,7 @@ def add_leadjet(pt,eta,phi,mass): _j.SetPtEtaPhiM(0,0,0,0) else: for i in range(len(pt)): - if (pt[i]>30 and abs(eta[i])<2.5 and pt[i] > _pTj1): + if (pt[i]>30 and abs(eta[i])<4.7 and pt[i] > _pTj1): _pTj1 = pt[i] index = i _j.SetPtEtaPhiM(_pTj1,eta[index],phi[index],mass[index]) @@ -207,7 +176,7 @@ def add_subleadjet(pt,eta,phi,mass,leadJet): _phij2 = 0.0 _j = ROOT.TLorentzVector() for i in range(len(pt)): - if (pt[i]>30 and abs(eta[i])<2.5 and pt[i] > _pTj2 and leadJet.Pt()-pt[i] > 0.00001): + if (pt[i]>30 and abs(eta[i])<4.7 and pt[i] > _pTj2 and leadJet.Pt()-pt[i] > 0.00001): _pTj2 = pt[i] _mj2 = mass[i] _etaj2 = eta[i] @@ -219,7 +188,7 @@ def add_subleadjet(pt,eta,phi,mass,leadJet): def count_jets(pt,eta,phi,mass): n = 0 for i in range(len(pt)): - if pt[i]>30 and abs(eta[i])<2.5: n = n + 1 + if pt[i]>30 and abs(eta[i])<4.7: n = n + 1 return n def varHiggsOneJets_jes(jet,Hmass,Heta,Hphi,Hpt): @@ -237,6 +206,24 @@ def tetra_Higgs(mass,eta,phi,pt): h.SetPtEtaPhiM(pt,eta,phi,mass) return h +def tc(pt,eta,phi,mass,H): + _TCjmax = 0 + for i in range(len(pt)): + theJet = ROOT.TLorentzVector() + theJet.SetPtEtaPhiM(pt[i],eta[i],phi[i],mass[i]); + _TCj = sqrt(theJet.Pt()**2 + theJet.M()**2)/(2*math.cosh(theJet.Rapidity() - H.Rapidity())) + if _TCj > _TCjmax: _TCjmax = _TCj + return _TCjmax + +def tb(pt,eta,phi,mass,H): + _TBjmax = 0 + for i in range(len(pt)): + theJet = ROOT.TLorentzVector() + theJet.SetPtEtaPhiM(pt[i],eta[i],phi[i],mass[i]); + _TBj = sqrt(theJet.Pt()**2 + theJet.M()**2)*math.exp(-1*(theJet.Rapidity() - H.Rapidity())); + if _TBj > _TBjmax: _TBjmax = _TBj + return _TBjmax + def createDataframe(dataFrame,isBkg,gen,xsec,signal,lumi,obs_reco,obs_reco_2nd='None'): b_sig = ['EventNumber', 'PUWeight', 'genHEPMCweight', @@ -245,9 +232,16 @@ def createDataframe(dataFrame,isBkg,gen,xsec,signal,lumi,obs_reco,obs_reco_2nd=' 'pTj1', 'Mj1', 'ETAj1', 'PHIj1', 'pTj2', 'Mj2', 'ETAj2', 'PHIj2'] - if not isBkg: b_sig += ['passedFiducialSelection_bbf','GENmass4l', 'GENlep_id', 'GENlep_MomId', 'GENlep_MomMomId', 'GENlep_Hindex', 'GENZ_DaughtersId', - 'GENZ_MomId', 'lep_Hindex', 'lep_genindex', 'GENpTj1', 'GENpTj2'] - if signal == 'ggH125': b_sig.append('ggH_NNLOPS_weight') #Additional entry for the weight in case of ggH + if obs_reco == 'ZZPt' or obs_reco_2nd == 'ZZPt': + b_sig.remove('ZZPt') + + if signal == 'ggH125': + b_sig.append('ggH_NNLOPS_weight') #Additional entry for the weight in case of ggH + elif signal == 'ZZTo4lext': + b_sig.append('KFactor_EW_qqZZ') + b_sig.append('KFactor_QCD_qqZZ_M') + elif 'gg' in signal: + b_sig.append('KFactor_QCD_ggZZ_Nominal') for i in jesNames: b_sig.extend(['JetPt_JESUp_'+i,'JetPt_JESDown_'+i]) if obs_reco != 'pTj1' and obs_reco != 'pTj2': b_sig.append(obs_reco) @@ -257,14 +251,6 @@ def createDataframe(dataFrame,isBkg,gen,xsec,signal,lumi,obs_reco,obs_reco_2nd=' df['gen'] = gen df['xsec'] = xsec df['FinState_reco'] = [add_fin_state_reco(i, j) for i,j in zip(df.Z1Flav, df.Z2Flav)] - if not isBkg: - df['FinState_gen'] = [add_fin_state_gen(row[0],row[1],row[2]) for row in df[['GENlep_id', 'GENlep_Hindex', 'EventNumber']].values] - if signal != 'ZH125': - df['FinState_gen_out'] = [add_fin_state_gen_out(i,j) for i,j in zip(df.GENZ_DaughtersId,df.EventNumber)] - else: - df['FinState_gen_out'] = [add_fin_state_gen_out_ZH(i,j) for i,j in zip(df.GENZ_DaughtersId,df.GENZ_MomId)] - df['cuth4l_gen'] = [add_cuth4l_gen(i,j) for i,j in zip(df.GENlep_MomMomId,df.GENlep_Hindex)] - df['cuth4l_reco'] = [add_cuth4l_reco(row[0],row[1],row[2],row[3]) for row in df[['lep_Hindex','lep_genindex','GENlep_MomMomId','GENlep_MomId']].values] # Leading jets for i in jesNames: df['j1_jesup_'+i] = [add_leadjet(row[0],row[1],row[2],row[3]) for row in df[['JetPt_JESUp_'+i,'JetEta','JetPhi','JetMass']].values] @@ -273,7 +259,6 @@ def createDataframe(dataFrame,isBkg,gen,xsec,signal,lumi,obs_reco,obs_reco_2nd=' for i in jesNames: df['j2_jesup_'+i] = [add_subleadjet(row[0],row[1],row[2],row[3],row[4]) for row in df[['JetPt_JESUp_'+i,'JetEta','JetPhi','JetMass','j1_jesup_'+i]].values] df['j2_jesdn_'+i] = [add_subleadjet(row[0],row[1],row[2],row[3],row[4]) for row in df[['JetPt_JESDown_'+i,'JetEta','JetPhi','JetMass','j1_jesdn_'+i]].values] - df['FinState_reco'] = [add_fin_state_reco(i, j) for i,j in zip(df.Z1Flav, df.Z2Flav)] # Calculus of up and down variations for observables different from leading jet df['Higgs'] = [tetra_Higgs(row[0],row[1],row[2],row[3]) for row in df[['ZZMass', 'ZZEta', 'ZZPhi', 'ZZPt']].values] for i in jesNames: @@ -284,23 +269,35 @@ def createDataframe(dataFrame,isBkg,gen,xsec,signal,lumi,obs_reco,obs_reco_2nd=' df['pTj2_jesup_'+i] = [x.Pt() for x in df['j2_jesup_'+i]] df['pTj2_jesdn_'+i] = [x.Pt() for x in df['j2_jesdn_'+i]] if 'njets' in obs_reco or 'njets' in obs_reco_2nd: - df['njets_pt30_eta2p5_jesup_'+i] = [count_jets(row[0],row[1],row[2],row[3]) for row in df[['JetPt_JESUp_'+i,'JetEta','JetPhi','JetMass']].values] - df['njets_pt30_eta2p5_jesdn_'+i] = [count_jets(row[0],row[1],row[2],row[3]) for row in df[['JetPt_JESDown_'+i,'JetEta','JetPhi','JetMass']].values] + df['njets_pt30_eta4p7_jesup_'+i] = [count_jets(row[0],row[1],row[2],row[3]) for row in df[['JetPt_JESUp_'+i,'JetEta','JetPhi','JetMass']].values] + df['njets_pt30_eta4p7_jesdn_'+i] = [count_jets(row[0],row[1],row[2],row[3]) for row in df[['JetPt_JESDown_'+i,'JetEta','JetPhi','JetMass']].values] if obs_reco == 'mjj' or obs_reco_2nd == 'mjj': - df['mjj_jesup_'+i] = [(j1+j2).M() for j1,j2 in zip(df['j1_jesup_'+i],df['j2_jesup_'+i])] - df['mjj_jesdn_'+i] = [(j1+j2).M() for j1,j2 in zip(df['j1_jesdn_'+i],df['j2_jesdn_'+i])] + df['mjj_jesup_'+i] = [(j1+j2).M() if j2.Pt()>0 else -1 for j1,j2 in zip(df['j1_jesup_'+i],df['j2_jesup_'+i])] + df['mjj_jesdn_'+i] = [(j1+j2).M() if j2.Pt()>0 else -1 for j1,j2 in zip(df['j1_jesdn_'+i],df['j2_jesdn_'+i])] if obs_reco == 'pTHj' or obs_reco_2nd == 'pTHj': - df['pTHj_jesup_'+i] = [(H+j1).Pt() for H,j1 in zip(df['Higgs'],df['j1_jesup_'+i])] - df['pTHj_jesdn_'+i] = [(H+j1).Pt() for H,j1 in zip(df['Higgs'],df['j1_jesdn_'+i])] + df['pTHj_jesup_'+i] = [(H+j1).Pt() if j1.Pt()>0 else -1 for H,j1 in zip(df['Higgs'],df['j1_jesup_'+i])] + df['pTHj_jesdn_'+i] = [(H+j1).Pt() if j1.Pt()>0 else -1 for H,j1 in zip(df['Higgs'],df['j1_jesdn_'+i])] if obs_reco == 'pTHjj' or obs_reco_2nd == 'pTHjj': - df['pTHjj_jesup_'+i] = [(row[0]+row[1]+row[2]).Pt() for row in df[['Higgs','j1_jesup_'+i,'j2_jesup_'+i]].values] - df['pTHjj_jesdn_'+i] = [(row[0]+row[1]+row[2]).Pt() for row in df[['Higgs','j1_jesdn_'+i,'j2_jesdn_'+i]].values] + df['pTHjj_jesup_'+i] = [(row[0]+row[1]+row[2]).Pt() if row[2].Pt()>0 else -1 for row in df[['Higgs','j1_jesup_'+i,'j2_jesup_'+i]].values] + df['pTHjj_jesdn_'+i] = [(row[0]+row[1]+row[2]).Pt() if row[2].Pt()>0 else -1 for row in df[['Higgs','j1_jesdn_'+i,'j2_jesdn_'+i]].values] if obs_reco == 'mHj' or obs_reco_2nd == 'mHj': - df['mHj_jesup_'+i] = [(H+j1).M() for H,j1 in zip(df['Higgs'],df['j1_jesup_'+i])] - df['mHj_jesdn_'+i] = [(H+j1).M() for H,j1 in zip(df['Higgs'],df['j1_jesdn_'+i])] + df['mHj_jesup_'+i] = [(H+j1).M() if j1.Pt()>0 else -1 for H,j1 in zip(df['Higgs'],df['j1_jesup_'+i])] + df['mHj_jesdn_'+i] = [(H+j1).M() if j1.Pt()>0 else -1 for H,j1 in zip(df['Higgs'],df['j1_jesdn_'+i])] if obs_reco == 'mHjj' or obs_reco_2nd == 'mHjj': - df['mHjj_jesup_'+i] = [(row[0]+row[1]+row[2]).M() for row in df[['Higgs','j1_jesup_'+i,'j2_jesup_'+i]].values] - df['mHjj_jesdn_'+i] = [(row[0]+row[1]+row[2]).M() for row in df[['Higgs','j1_jesdn_'+i,'j2_jesdn_'+i]].values] + df['mHjj_jesup_'+i] = [(row[0]+row[1]+row[2]).M() if row[2].Pt()>0 else -1 for row in df[['Higgs','j1_jesup_'+i,'j2_jesup_'+i]].values] + df['mHjj_jesdn_'+i] = [(row[0]+row[1]+row[2]).M() if row[2].Pt()>0 else -1 for row in df[['Higgs','j1_jesdn_'+i,'j2_jesdn_'+i]].values] + if obs_reco == 'absdetajj' or obs_reco_2nd == 'absdetajj': + df['absdetajj_jesup_'+i] = [abs(j1.Eta()-j2.Eta()) if j2.Pt()>0 else -1 for j1,j2 in zip(df['j1_jesup_'+i],df['j2_jesup_'+i])] + df['absdetajj_jesdn_'+i] = [abs(j1.Eta()-j2.Eta()) if j2.Pt()>0 else -1 for j1,j2 in zip(df['j1_jesdn_'+i],df['j2_jesdn_'+i])] + if obs_reco == 'ZZPt' or obs_reco_2nd == 'ZZPt': + df['ZZPt_jesup_'+i] = df['ZZPt'] + df['ZZPt_jesdn_'+i] = df['ZZPt'] + if obs_reco == 'TCjmax' or obs_reco_2nd == 'TCjmax': + df['TCjmax_jesup_'+i] = [tc(row[0],row[1],row[2],row[3],row[4]) for row in df[['JetPt_JESUp_'+i,'JetEta','JetPhi','JetMass','Higgs']].values] + df['TCjmax_jesdn_'+i] = [tc(row[0],row[1],row[2],row[3],row[4]) for row in df[['JetPt_JESDown_'+i,'JetEta','JetPhi','JetMass','Higgs']].values] + if obs_reco == 'TBjmax' or obs_reco_2nd == 'TBjmax': + df['TBjmax_jesup_'+i] = [tb(row[0],row[1],row[2],row[3],row[4]) for row in df[['JetPt_JESUp_'+i,'JetEta','JetPhi','JetMass','Higgs']].values] + df['TBjmax_jesdn_'+i] = [tb(row[0],row[1],row[2],row[3],row[4]) for row in df[['JetPt_JESDown_'+i,'JetEta','JetPhi','JetMass','Higgs']].values] if signal != 'ggH125': df = weight(df, xsec, gen, lumi) diff --git a/helperstuff/observables.py b/helperstuff/observables.py new file mode 100644 index 0000000..a32a566 --- /dev/null +++ b/helperstuff/observables.py @@ -0,0 +1,119 @@ +observables = { +'mass4l': + {'obs_reco': 'ZZMass', + 'obs_gen': 'GENmass4l'}, +'mass4l_zzfloating': + {'obs_reco': 'ZZMass', + 'obs_gen': 'GENmass4l'}, +'njets_pt30_eta4p7': + {'obs_reco': 'njets_pt30_eta4p7', + 'obs_gen': 'GENnjets_pt30_eta4p7'}, +'pT4l': + {'obs_reco': 'ZZPt', + 'obs_gen': 'GENpT4l'}, +'rapidity4l': + {'obs_reco': 'ZZy', + 'obs_gen': 'GENrapidity4l'}, +'costhetaZ1': + {'obs_reco': 'helcosthetaZ1', + 'obs_gen': 'GENcosTheta1'}, +'costhetaZ2': + {'obs_reco': 'helcosthetaZ2', + 'obs_gen': 'GENcosTheta2'}, +'phi': + {'obs_reco': 'helphi', + 'obs_gen': 'GENPhi'}, +'phistar': + {'obs_reco': 'phistarZ1', + 'obs_gen': 'GENPhi1'}, +'costhetastar': + {'obs_reco': 'costhetastar', + 'obs_gen': 'GENcosThetaStar'}, +'massZ1': + {'obs_reco': 'Z1Mass', + 'obs_gen': 'GENmassZ1'}, +'massZ2': + {'obs_reco': 'Z2Mass', + 'obs_gen': 'GENmassZ2'}, +'pTj1': + {'obs_reco': 'pTj1', + 'obs_gen': 'GENpTj1'}, +'pTHj': + {'obs_reco': 'pTHj', + 'obs_gen': 'GENpTHj'}, +'mHj': + {'obs_reco': 'mHj', + 'obs_gen': 'GENmHj'}, +'pTj2': + {'obs_reco': 'pTj2', + 'obs_gen': 'GENpTj2'}, +'mjj': + {'obs_reco': 'mjj', + 'obs_gen': 'GENmjj'}, +'absdetajj': + {'obs_reco': 'absdetajj', + 'obs_gen': 'GENabsdetajj'}, +'dphijj': + {'obs_reco': 'dphijj', + 'obs_gen': 'GENdphijj'}, +'pTHjj': + {'obs_reco': 'pTHjj', + 'obs_gen': 'GENpTHjj'}, +'TCjmax': { + 'obs_reco': 'TCjmax', + 'obs_gen': 'GENTCjmax'}, +'TBjmax': { + 'obs_reco': 'TBjmax', + 'obs_gen': 'GENTBjmax'}, +'D0m': + {'obs_reco': 'D0m', + 'obs_gen': 'GEN_D0m'}, +'Dcp': + {'obs_reco': 'Dcp', + 'obs_gen': 'GEN_Dcp'}, +'D0hp': + {'obs_reco': 'D0hp', + 'obs_gen': 'GEN_D0hp'}, +'Dcp': + {'obs_reco': 'Dcp', + 'obs_gen': 'GEN_Dcp'}, +'Dint': + {'obs_reco': 'Dint', + 'obs_gen': 'GEN_Dint'}, +'DL1': + {'obs_reco': 'DL1', + 'obs_gen': 'GEN_DL1'}, +'DL1Zg': + {'obs_reco': 'DL1Zg', + 'obs_gen': 'GEN_DL1Zg'}, +'rapidity4l vs pT4l': + {'obs_reco': 'ZZy', + 'obs_reco_2nd': 'ZZPt', + 'obs_gen': 'GENrapidity4l', + 'obs_gen_2nd': 'GENpT4l'}, +'njets_pt30_eta4p7 vs pT4l': + {'obs_reco': 'njets_pt30_eta4p7', + 'obs_reco_2nd': 'ZZPt', + 'obs_gen': 'GENnjets_pt30_eta4p7', + 'obs_gen_2nd': 'GENpT4l'}, +'pTj1 vs pTj2': + {'obs_reco': 'pTj1', + 'obs_reco_2nd': 'pTj2', + 'obs_gen': 'GENpTj1', + 'obs_gen_2nd': 'GENpTj2'}, +'pT4l vs pTHj': + {'obs_reco': 'ZZPt', + 'obs_reco_2nd': 'pTHj', + 'obs_gen': 'GENpT4l', + 'obs_gen_2nd': 'GENpTHj'}, +'massZ1 vs massZ2': + {'obs_reco': 'Z1Mass', + 'obs_reco_2nd': 'Z2Mass', + 'obs_gen': 'GENmassZ1', + 'obs_gen_2nd': 'GENmassZ2'}, +'TCjmax vs pT4l': + {'obs_reco_2nd': 'TCjmax', + 'obs_gen_2nd': 'GENTCjmax', + 'obs_reco': 'ZZPt', + 'obs_gen': 'GENpT4l'}, +} diff --git a/inputs/binning.py b/inputs/binning.py index b89114a..0fa5d71 100644 --- a/inputs/binning.py +++ b/inputs/binning.py @@ -1,4 +1,4 @@ -binning = {'rapidity4l': '|0.0|0.15|0.3|0.6|0.9|1.2|2.5|',#'|0.0|0.15|0.3|0.45|0.6|0.75|0.9|1.2|1.6|2.0|2.5|', +list = {'rapidity4l': '|0.0|0.15|0.3|0.6|0.9|1.2|2.5|',#'|0.0|0.15|0.3|0.45|0.6|0.75|0.9|1.2|1.6|2.0|2.5|', 'pT4l': '|0|10|20|30|45|60|80|120|200|13000|', 'massZ1': '|50|64|73|85|106|', 'massZ2': '|12|20|24|28|32|40|55|65|', @@ -33,3 +33,77 @@ 'njets_pt30_eta2p5 vs TCjmax': '|0|1|10| vs |-1|1| / |0|15|30|50|70|90|1000|' # 'njets_pt30_eta2p5 vs absdphijj': '|0|2|10| vs |0|800| / ||' # Decide if we want to go to 2PI or to PI } + + +def binning(var): + obsBins_input = list[var] + print('input', obsBins_input) + if not 'vs' in obsBins_input: #It is not a double-differential analysis + obs_bins = {0:(obsBins_input.split("|")[1:(len(obsBins_input.split("|"))-1)]),1:['0','inf']}[obsBins_input=='inclusive'] + obs_bins = [float(i) for i in obs_bins] #Convert a list of str to a list of float + doubleDiff = False + print ('It is a single-differential measurement, binning', obs_bins) + else: #It is a double-differential analysis + doubleDiff = True + # The structure of obs_bins is: + # index of the dictionary is the number of the bin + # [obs_bins_low, obs_bins_high, obs_bins_low_2nd, obs_bins_high_2nd] + # The first two entries are the lower and upper bound of the first variable + # The second two entries are the lower and upper bound of the second variable + if obsBins_input.count('vs')==1 and obsBins_input.count('/')>=1: #Situation like this one '|0|1|2|3|20| vs |0|10|20|45|90|250| / |0|10|20|80|250| / |0|20|90|250| / |0|25|250|' + obs_bins_tmp = obsBins_input.split(" vs ") #['|0|1|2|3|20|', '|0|10|20|45|90|250| / |0|10|20|80|250| / |0|20|90|250| / |0|25|250|'] + obs_bins_1st = obs_bins_tmp[0].split('|')[1:len(obs_bins_tmp[0].split('|'))-1] #['0', '1', '2', '3', '20'] + obs_bins_1st = [float(i) for i in obs_bins_1st] #Convert a list of str to a list of float + obs_bins_tmp = obs_bins_tmp[1].split(' / ') #['|0|10|20|45|90|250|', '|0|10|20|80|250|', '|0|20|90|250|', '|0|25|250|'] + obs_bins_2nd = {} + for i in range(len(obs_bins_tmp)): #At the end of the loop -> obs_bins_2nd {0: ['0', '10', '20', '45', '90', '250'], 1: ['0', '10', '20', '80', '250'], 2: ['0', '20', '90', '250'], 3: ['0', '25', '250']} + obs_bins_2nd[i] = obs_bins_tmp[i].split('|')[1:len(obs_bins_tmp[i].split('|'))-1] + obs_bins_2nd[i] = [float(j) for j in obs_bins_2nd[i]] #Convert a list of str to a list of float + obs_bins = {} + k = 0 #Bin index + for i in range(len(obs_bins_1st)-1): + for j in range(len(obs_bins_2nd[i])-1): + obs_bins[k] = [] + obs_bins[k].append(obs_bins_1st[i]) + obs_bins[k].append(obs_bins_1st[i+1]) + obs_bins[k].append(obs_bins_2nd[i][j]) + obs_bins[k].append(obs_bins_2nd[i][j+1]) + k +=1 + elif obsBins_input.count('vs')>1 and obsBins_input.count('/')>1: #Situation like this one '|50|80| vs |10|30| / |50|80| vs |30|60| / |80|110| vs |10|25| / |80|110| vs |25|30|' + obs_bins_tmp = obsBins_input.split(' / ') #['|50|80| vs |10|30|', '|50|80| vs |30|60|', '|80|110| vs |10|25|', '|80|110| vs |25|30|'] + obs_bins_1st={} + obs_bins_2nd={} + obs_bins={} + for i in range(len(obs_bins_tmp)): #At the end of the loop -> obs_bins_1st {0: ['50', '80'], 1: ['50', '80'], 2: ['80', '110'], 3: ['80', '110']} and obs_bins_2nd {0: ['10', '30'], 1: ['30', '60'], 2: ['10', '25'], 3: ['25', '30']} + obs_bins_tmp_bis = obs_bins_tmp[i].split(' vs ') + obs_bins_1st[i] = obs_bins_tmp_bis[0].split('|')[1:len(obs_bins_tmp_bis[0].split('|'))-1] + obs_bins_1st[i] = [float(j) for j in obs_bins_1st[i]] #Convert a list of str to a list of float + obs_bins_2nd[i] = obs_bins_tmp_bis[1].split('|')[1:len(obs_bins_tmp_bis[1].split('|'))-1] + obs_bins_2nd[i] = [float(j) for j in obs_bins_2nd[i]] #Convert a list of str to a list of float + obs_bins[i] = [] + obs_bins[i].append(obs_bins_1st[i][0]) + obs_bins[i].append(obs_bins_1st[i][1]) + obs_bins[i].append(obs_bins_2nd[i][0]) + obs_bins[i].append(obs_bins_2nd[i][1]) + elif obsBins_input.count('vs')==1 and obsBins_input.count('/')==0: #Situation like this one '|0|1|2|3|20| vs |0|10|20|45|90|250|' + obs_bins_tmp = obsBins_input.split(" vs ") #['|0|1|2|3|20|', '|0|10|20|45|90|250|'] + obs_bins_1st = obs_bins_tmp[0].split('|')[1:len(obs_bins_tmp[0].split('|'))-1] #['0', '1', '2', '3', '20'] + obs_bins_1st = [float(i) for i in obs_bins_1st] #Convert a list of str to a list of float + obs_bins_2nd = obs_bins_tmp[1].split('|')[1:len(obs_bins_tmp[1].split('|'))-1] #['0', '10', '20', '45', '90', '250'] + obs_bins_2nd = [float(i) for i in obs_bins_2nd] #Convert a list of str to a list of float + obs_bins = {} + k = 0 #Bin index + for i in range(len(obs_bins_1st)-1): + for j in range(len(obs_bins_2nd)-1): + obs_bins[k] = [] + obs_bins[k].append(obs_bins_1st[i]) + obs_bins[k].append(obs_bins_1st[i+1]) + obs_bins[k].append(obs_bins_2nd[j]) + obs_bins[k].append(obs_bins_2nd[j+1]) + k +=1 + else: + print ('Problem in the definition of the binning') + quit() + print ('It is a double-differential measurement, binning for the 1st variable', obs_bins_1st, 'and for the 2nd variable', obs_bins_2nd) + print (obs_bins) + return obs_bins, doubleDiff diff --git a/producePlots.py b/producePlots.py index c7e43c5..6d37909 100644 --- a/producePlots.py +++ b/producePlots.py @@ -85,7 +85,7 @@ def plotXS(obsName, obs_bins, obs_bins_boundaries = False): higgs4l_br = _temp.higgs4l_br if (opt.FIXFRAC): floatfix = '_fixfrac' else: floatfix = '' - if (obsName == "mass4l"): + if (obsName.startswith("mass4l")): if opt.UNBLIND: _temp = __import__('resultsXS_LHScan_observed_'+obsName+'_v3'+floatfix, globals(), locals(), ['resultsXS'], -1) else: _temp = __import__('resultsXS_LHScan_expected_'+obsName+'_v3'+floatfix, globals(), locals(), ['resultsXS'], -1) # modelNames = _temp.modelNames @@ -466,7 +466,7 @@ def plotXS(obsName, obs_bins, obs_bins_boundaries = False): total_NNLOunc_fs_minloHJ_hi += XH_qcdunc_fs total_NNLOunc_fs_minloHJ_lo += XH_qcdunc_fs - if (obsName=="mass4l"): + if (obsName.startswith("mass4l")): total_NNLOunc_fs_minloHJ_hi += (unc_qcd_ggH_hi *ggH_xsBR*acc_NNLOPS['ggH125_NNLOPS_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 total_NNLOunc_fs_minloHJ_lo += (unc_qcd_ggH_lo @@ -513,7 +513,7 @@ def plotXS(obsName, obs_bins, obs_bins_boundaries = False): # add pdf unc, anti correlate ggH and ttH #NNLO - if (obsName=="mass4l"): + if (obsName.startswith("mass4l")): obsUnc_pdf_ggH_hi = unc_pdf_ggH_hi obsUnc_pdf_ggH_lo = unc_pdf_ggH_lo else: @@ -626,7 +626,7 @@ def plotXS(obsName, obs_bins, obs_bins_boundaries = False): data_hi_allunc[obsBin] = sqrt(data_hi[obsBin]**2+modeldep_hi[obsBin]**2) data_lo_allunc[obsBin] = sqrt(data_lo[obsBin]**2+modeldep_lo[obsBin]**2) - if (obsName=="mass4l"): + if (obsName.startswith("mass4l")): for channel in ['2e2mu','4mu','4e']: # theory cross sections @@ -778,7 +778,7 @@ def plotXS(obsName, obs_bins, obs_bins_boundaries = False): #modeldep_lo[bin] = -1.0*modelIndUncert_v2["AsimovData_"+obsName+"_"+channel+"_genbin"+str(obsBin)]["uncerDn"] #systematics_hi[bin] = sqrt(resultsXS_v2["AsimovData_"+obsName+"_"+channel+"_genbin"+str(obsBin)]["uncerUp"]**2-resultsXS_v2["AsimovData_"+obsName+"_"+channel+"_genbin"+str(obsBin)+'_statOnly']["uncerUp"]**2) #systematics_lo[bin] = sqrt(resultsXS_v2["AsimovData_"+obsName+"_"+channel+"_genbin"+str(obsBin)]["uncerDn"]**2-resultsXS_v2["AsimovData_"+obsName+"_"+channel+"_genbin"+str(obsBin)+'_statOnly']["uncerDn"]**2) - if (obsName=="mass4l"): + if (obsName.startswith("mass4l")): # modeldep_hi[bin] = modelIndUncert_v2["AsimovData_"+obsName+"_"+channel+"_genbin"+str(obsBin)]["uncerUp"] # modeldep_lo[bin] = -1.0*modelIndUncert_v2["AsimovData_"+obsName+"_"+channel+"_genbin"+str(obsBin)]["uncerDn"] systematics_hi[bin] = sqrt(resultsXS_v2[datamodel+"_"+obsName+"_"+channel+"_genbin"+str(obsBin)]["uncerUp"]**2-resultsXS_v2[datamodel+"_"+obsName+"_"+channel+"_genbin"+str(obsBin)+'_statOnly']["uncerUp"]**2) @@ -838,7 +838,7 @@ def plotXS(obsName, obs_bins, obs_bins_boundaries = False): print 'systematics_lo',systematics_lo print 'stat_hi',stat_hi print 'stat_lo',stat_lo - if (obsName=="mass4l"): + if (obsName.startswith("mass4l")): offset = 0.0 a_observable = array('d',[0.5+i for i in range(0,4)]) @@ -1130,7 +1130,7 @@ def plotXS(obsName, obs_bins, obs_bins_boundaries = False): g_ggH_powhege0.SetLineColor(ROOT.kAzure+2) g_ggH_powhege0.SetMarkerColor(ROOT.kAzure+2) - if (obsName=="mass4l"): + if (obsName.startswith("mass4l")): g_ggH_powheg = TGraphAsymmErrors(v_observable_1,v_ggH_powheg,v_dobservable_1,v_dobservable_1,v_ggH_powheg_unc_lo,v_ggH_powheg_unc_hi) g_ggH_powheg.SetFillStyle(3254); @@ -1162,8 +1162,8 @@ def plotXS(obsName, obs_bins, obs_bins_boundaries = False): g_ggH_powhegBorder.SetLineColor(ROOT.kAzure+2) g_ggH_powhegBorder.SetMarkerColor(ROOT.kAzure+2) - h_ggH_powheg = TH1D("h_ggH_powheg","h_ggH_powheg",5, 0, 5) - for i in range(5): + h_ggH_powheg = TH1D("h_ggH_powheg","h_ggH_powheg",4, 0, 4) + for i in range(4): h_ggH_powheg.SetBinContent(i+1,v_ggH_powheg[i]) else: g_ggH_powheg = TGraphAsymmErrors(v_observable_1,v_ggH_powheg,v_dobservable_1,v_dobservable_1,v_ggH_powheg_unc_lo,v_ggH_powheg_unc_hi) @@ -1256,7 +1256,7 @@ def plotXS(obsName, obs_bins, obs_bins_boundaries = False): g_ggH_minloHJe0.SetLineColor(ROOT.kOrange+2) g_ggH_minloHJe0.SetMarkerColor(ROOT.kOrange+2) - if (obsName=="mass4l"): + if (obsName.startswith("mass4l")): h_ggH_minloHJ = TH1D("h_ggH_minloHJ","h_ggH_minloHJ",4, 0, 4) for i in range(4): h_ggH_minloHJ.SetBinContent(i+1,v_ggH_minloHJ[i]) @@ -1278,7 +1278,7 @@ def plotXS(obsName, obs_bins, obs_bins_boundaries = False): g_ggH_minloHJBorder.SetLineColor(ROOT.kOrange+2) g_ggH_minloHJBorder.SetMarkerColor(ROOT.kOrange+2) - if (not obsName =="mass4l" and not doubleDiff): + if (not obsName.startswith("mass4l") and not doubleDiff): if ("jet" in obsName and (not obsName.startswith("njets"))): h_ggH_minloHJ = TH1D("h_ggH_minloHJ","h_ggH_minloHJ",nBins-2, array('d',[float(obs_bins[i]) for i in range(1,len(obs_bins))]) ) for i in range(1,nBins-1): @@ -1437,7 +1437,7 @@ def plotXS(obsName, obs_bins, obs_bins_boundaries = False): g_ratio_powhege0.SetLineWidth(2) g_ratio_powhege0.SetMarkerColor(ROOT.kAzure+2) - if (obsName=="mass4l"): + if (obsName.startswith("mass4l")): g_ratio_powheg = TGraphAsymmErrors(v_observable_1,v_ratio_powheg,v_dobservable_1,v_dobservable_1,v_ratio_powheg_lo,v_ratio_powheg_hi) g_ratio_powheg.SetFillStyle(3254); g_ratio_powheg.SetFillColor(ROOT.kAzure+2) @@ -1468,8 +1468,8 @@ def plotXS(obsName, obs_bins, obs_bins_boundaries = False): g_ratio_powhegBorder.SetLineColor(ROOT.kAzure+2) g_ratio_powhegBorder.SetMarkerColor(ROOT.kAzure+2) - h_ratio_powheg = TH1D("h_ratio_powheg","h_ratio_powheg",5, 0, 5) - for i in range(5): + h_ratio_powheg = TH1D("h_ratio_powheg","h_ratio_powheg",4, 0, 4) + for i in range(4): h_ratio_powheg.SetBinContent(i+1,v_ratio_powheg[i]) else: g_ratio_powheg = TGraphAsymmErrors(v_observable_1,v_ratio_powheg,v_dobservable_1,v_dobservable_1,v_ratio_powheg_lo,v_ratio_powheg_hi) @@ -1517,7 +1517,7 @@ def plotXS(obsName, obs_bins, obs_bins_boundaries = False): # g_ratio_minloHJe0.SetLineWidth(2) # g_ratio_minloHJe0.SetMarkerColor(ROOT.kOrange+2) - if (obsName=="mass4l"): + if (obsName.startswith("mass4l")): g_ratio_minloHJ = TGraphAsymmErrors(v_observable_2,v_ratio_minloHJ,v_dobservable_2,v_dobservable_2,v_ratio_minloHJ_lo,v_ratio_minloHJ_hi) g_ratio_minloHJ.SetFillStyle(3245); @@ -1550,8 +1550,8 @@ def plotXS(obsName, obs_bins, obs_bins_boundaries = False): g_ratio_minloHJBorder.SetLineColor(ROOT.kOrange+2) g_ratio_minloHJBorder.SetMarkerColor(ROOT.kOrange+2) - h_ratio_minloHJ = TH1D("h_ratio_minloHJ","h_ratio_minloHJ",5, 0, 5) - for i in range(5): + h_ratio_minloHJ = TH1D("h_ratio_minloHJ","h_ratio_minloHJ",4, 0, 4) + for i in range(4): h_ratio_minloHJ.SetBinContent(i+1,v_ratio_minloHJ[i]) elif acFlag: # We keep the same names as in the last else (just to reduce entropy with if statements) g_ratio_minloHJ = TGraphAsymmErrors(v_observable_2,v_ratio_AC,v_dobservable_2,v_dobservable_2,v_ratio_AC_lo,v_ratio_AC_hi) @@ -1696,7 +1696,7 @@ def plotXS(obsName, obs_bins, obs_bins_boundaries = False): elif (obsName=="phistar"): label = "|#Phi_{1}|" unit = "" - elif (obsName=="mass4l"): + elif (obsName.startswith("mass4l")): label = "inclusive" unit = "" elif obsName=='massZ1_massZ2': @@ -1725,12 +1725,12 @@ def plotXS(obsName, obs_bins, obs_bins_boundaries = False): c = TCanvas("c",obsName, 1400, 1400) if(opt.SETLOG): c.SetLogy() - if (not obsName=="mass4l"): c.SetBottomMargin(0.35) + if (not obsName.startswith("mass4l")): c.SetBottomMargin(0.35) c.SetRightMargin(0.04) c.SetTopMargin(0.07) c.SetLeftMargin(0.18) - if (obsName=="mass4l"): + if (obsName.startswith("mass4l")): dummy = TH1D("dummy","dummy", 4, 0, 4) for i in range(1,5): dummy.SetBinContent(i,2.5*max(a_ggH_powheg)) @@ -1775,7 +1775,7 @@ def plotXS(obsName, obs_bins, obs_bins_boundaries = False): elif (obsName=="DL1"): dummy.SetMaximum(1100*max(max(a_data),(max(a_ggH_powheg)))) else: dummy.SetMaximum(55.0*max(max(a_data),(max(a_ggH_powheg)))) else: - if (obsName=="mass4l") or doubleDiff: dummy.SetMaximum(1.6*(max(max(a_data),(max(a_ggH_powheg)))+max(a_data_hi))) + if (obsName.startswith("mass4l")) or doubleDiff: dummy.SetMaximum(1.6*(max(max(a_data),(max(a_ggH_powheg)))+max(a_data_hi))) if doubleDiff: dummy.SetMaximum(2.0*(max(max(a_data),(max(a_ggH_powheg)))+max(a_data_hi))) elif (obsName=="massZ2"): dummy.SetMaximum(2.0*(max(max(a_data),(max(a_ggH_powheg)))+max(a_data_hi))) #AT elif (obsName=="massZ1"): dummy.SetMaximum(2.0*(max(max(a_data),(max(a_ggH_powheg)))+max(a_data_hi))) #AT @@ -1806,7 +1806,7 @@ def plotXS(obsName, obs_bins, obs_bins_boundaries = False): dummy.GetXaxis().SetBinLabel(2,'') dummy.GetXaxis().SetBinLabel(3,'') dummy.GetXaxis().SetBinLabel(4,'') - if (obsName=="mass4l"): + if (obsName.startswith("mass4l")): dummy.GetXaxis().SetLabelSize(0.08) dummy.GetXaxis().SetBinLabel(1,'4l') dummy.GetXaxis().SetBinLabel(2,'2e2#mu') @@ -1963,7 +1963,7 @@ def plotXS(obsName, obs_bins, obs_bins_boundaries = False): dummy.Draw("axissame") - if (not obsName=="mass4l"): + if (not obsName.startswith("mass4l")): pad = TPad("pad", "pad", 0.0, 0.0, 1.0, 1.0) pad.SetTopMargin(0.65) pad.SetRightMargin(0.04) @@ -1974,7 +1974,7 @@ def plotXS(obsName, obs_bins, obs_bins_boundaries = False): pad.Draw() pad.cd(0) - if (obsName=="mass4l"): + if (obsName.startswith("mass4l")): dummy2 = TH1D("dummy2","dummy2", 4, 0, 4) for i in range(1,5): dummy2.SetBinContent(i,1.02) diff --git a/producePlots_v4.py b/producePlots_v4.py new file mode 100644 index 0000000..f16ff97 --- /dev/null +++ b/producePlots_v4.py @@ -0,0 +1,2202 @@ +import sys, os, string, re, pwd, commands, ast, optparse, shlex, time +from array import array +from math import * +from decimal import * +#from sample_shortnames import * +def checkDir(folder_path): + isdir = os.path.isdir(folder_path) + if not isdir: + print('Directory {} does not exist. Creating it.' .format(folder_path)) + os.mkdir(folder_path) + +grootargs = [] +def callback_rootargs(option, opt, value, parser): + grootargs.append(opt) + +### Define function for parsing options +def parseOptions(): + + global opt, args, runAllSteps + + usage = ('usage: %prog [options]\n' + + '%prog -h for help') + parser = optparse.OptionParser(usage) + + # input options + parser.add_option('-d', '--dir', dest='SOURCEDIR', type='string',default='./', help='run from the SOURCEDIR as working area, skip if SOURCEDIR is an empty string') + parser.add_option('', '--unfoldModel',dest='UNFOLD',type='string',default='SM_125', help='Name of the unfolding model for central value') + parser.add_option('', '--obsName',dest='OBSNAME', type='string',default='', help='Name of the observalbe, supported: "inclusive", "pT", "eta", "Njets"') + parser.add_option('', '--obsBins',dest='OBSBINS', type='string',default='', help='Bin boundaries for the diff. measurement separated by "|", e.g. as "|0|50|100|", use the defalut if empty string') + parser.add_option('', '--theoryMass',dest='THEORYMASS', type='string',default='125.38', help='Mass value for theory prediction') + parser.add_option('', '--fixFrac', action='store_true', dest='FIXFRAC', default=False, help='Use results from fixed fraction fit, default is False') + parser.add_option('', '--setLog', action='store_true', dest='SETLOG', default=False, help='set plot to log scale y, default is False') + parser.add_option('', '--unblind', action='store_true', dest='UNBLIND', default=False, help='Use real data') + parser.add_option('', '--lumiscale', type='string', dest='LUMISCALE', default='1.0', help='Scale yields') + parser.add_option('', '--year', dest='YEAR', type='string',default='', help='Year -> 2016 or 2017 or 2018 or Full') + parser.add_option("-l",action="callback",callback=callback_rootargs) + parser.add_option("-q",action="callback",callback=callback_rootargs) + parser.add_option("-b",action="callback",callback=callback_rootargs) + + # store options and arguments as global variables + global opt, args + (opt, args) = parser.parse_args() + +# parse the arguments and options +global opt, args, runAllSteps +parseOptions() +sys.argv = grootargs + +if (not os.path.exists("plots")): + os.system("mkdir plots") + +from ROOT import * + +from tdrStyle import * +setTDRStyle() + +datamodel = opt.UNFOLD + +sys.path.append('./inputs') +sys.path.append('./LHScans') + +def plotXS(obsName, obs_bins, chan, obs_bins_boundaries = False): + + _temp = __import__('inputs_sig_'+obsName+'_'+opt.YEAR, globals(), locals(), ['acc'], -1) + acc = _temp.acc + print 'inputs_sig_'+obsName+'_'+opt.YEAR + # eff = _temp.eff + # outinratio = _temp.outinratio + if(opt.YEAR=='Full'): + _temp = __import__('inputs_sig_'+obsName+'_NNLOPS_Full', globals(), locals(), ['acc'], -1) + acc_NNLOPS = _temp.acc + else: + _temp = __import__('inputs_sig_'+obsName+'_NNLOPS_'+opt.YEAR, globals(), locals(), ['acc'], -1) + acc_NNLOPS = _temp.acc + + if(acFlag): + _temp = __import__('inputs_sig_ACggH_'+acSample+'_'+obsName+'_Full', globals(), locals(), ['acc'], -1) + acc_AC = _temp.acc + if(acFlagBis): + _temp = __import__('inputs_sig_ACggH_'+acSampleBis+'_'+obsName+'_Full', globals(), locals(), ['acc'], -1) + acc_ACbis = _temp.acc + + _temp = __import__('higgs_xsbr_13TeV', globals(), locals(), ['higgs_xs','higgs4l_br'], -1) + higgs_xs = _temp.higgs_xs + higgs4l_br = _temp.higgs4l_br + if (opt.FIXFRAC): floatfix = '_fixfrac' + else: floatfix = '' + + if (opt.UNBLIND): _temp = __import__('resultsXS_LHScan_observed_'+obsName+'_v4'+floatfix, globals(), locals(), ['resultsXS'], -1) + else: _temp = __import__('resultsXS_LHScan_expected_'+obsName+'_v4'+floatfix, globals(), locals(), ['resultsXS'], -1) + resultsXS = _temp.resultsXS + + + # Calculation of coefficients to scale ggH acceptances + if(acFlag): + accCorrFact = {} + for pmode in ['VBFH125', 'WH125', 'ZH125', 'ttH125']: + for fState in ['2e2mu', '4e', '4mu']: + for obsBin in range(len(obs_bins)-1): + # if opt.TUNEAC: + # accCorrFact[pmode+'_'+fState+'_genbin'+str(obsBin)] = acc[pmode+'_'+fState+'_'+obsName+'_genbin'+str(obsBin)+'_recobin0'] / acc['ggH125_'+fState+'_'+obsName+'_genbin'+str(obsBin)+'_recobin0'] + # print pmode+'_'+fState+'_genbin'+str(obsBin), accCorrFact[pmode+'_'+fState+'_genbin'+str(obsBin)] + # else: + accCorrFact[pmode+'_'+fState+'_genbin'+str(obsBin)] = 1 + + + #print _temp + #print resultsXS + + # acc_ggH_powheg = {} + pdfunc_ggH_powheg = {} + qcdunc_ggH_powheg = {} + _temp = __import__('accUnc_'+obsName, globals(), locals(), ['pdfUncert','qcdUncert'], -1) + # acc_ggH_powheg = _temp.acc #AT Non viene mai usato + pdfunc_ggH_powheg = _temp.pdfUncert + qcdunc_ggH_powheg = _temp.qcdUncert + if not acFlag: + _temp = __import__('accUnc_'+obsName+'_NNLOPS', globals(), locals(), ['pdfUncert','qcdUncert'], -1) + pdfunc_ggH_nnlops = _temp.pdfUncert + qcdunc_ggH_nnlops = _temp.qcdUncert + else: + _temp = __import__('accUnc_'+obsName+'_NNLOPS', globals(), locals(), ['pdfUncert','qcdUncert'], -1) + pdfunc_ggH_nnlops = _temp.pdfUncert + qcdunc_ggH_nnlops = _temp.qcdUncert + + # cross sections + ggH_powheg = [] + ggH_powheg_unc_hi = [] + ggH_powheg_unc_lo = [] + ggH_minloHJ = [] + ggH_minloHJ_unc_hi = [] + ggH_minloHJ_unc_lo = [] + # ggH_HRes = [] + # ggH_HRes_unc_hi = [] + # ggH_HRes_unc_lo = [] + # NNLO theory unc + ggH_powheg_NNLOunc_hi = [] + ggH_powheg_NNLOunc_lo = [] + ggH_minloHJ_NNLOunc_hi = [] + ggH_minloHJ_NNLOunc_lo = [] + # ggH_HRes_NNLOunc_hi = [] + # ggH_HRes_NNLOunc_lo = [] + # NLO theory unc + ggH_powheg_NLOunc_hi = [] + ggH_powheg_NLOunc_lo = [] + ggH_minloHJ_NLOunc_hi = [] + ggH_minloHJ_NLOunc_lo = [] + # AC predictions + if(acFlag): + ggH_AC = [] + ggH_AC_unc_hi = [] + ggH_AC_unc_lo = [] + ggH_AC_NNLOunc_hi = [] + ggH_AC_NNLOunc_lo = [] + ggH_AC_NLOunc_hi = [] + ggH_AC_NLOunc_lo = [] + XH_AC = [] + XH_AC_unc = [] + if(acFlagBis): + ggH_ACbis = [] + ggH_ACbis_unc_hi = [] + ggH_ACbis_unc_lo = [] + ggH_ACbis_NNLOunc_hi = [] + ggH_ACbis_NNLOunc_lo = [] + ggH_ACbis_NLOunc_hi = [] + ggH_ACbis_NLOunc_lo = [] + XH_ACbis = [] + XH_ACbis_unc = [] + # XH unc + XH = [] + XH_unc = [] + # Data + data = [] + data_hi = [] + data_lo = [] + data_hi2 = [] + data_lo2 = [] + asimovdata = [] + # Systematic unc. + systematics_hi = [] + systematics_lo = [] + systematics_hi2 = [] + systematics_lo2 = [] + modeldep_hi = [] + modeldep_lo = [] + data_hi_allunc = [] + data_lo_allunc = [] + stat_hi = [] + stat_lo = [] + + #process ggH qqH WH ZH ttH bkg_qqzz bkg_ggzz bkg_zjets + #pdf_gg lnN 1.0720 - - - 1.0780 - 1.0710 - + #pdf_qqbar lnN - 1.0270 1.0350 1.0350 - 1.0342 - - + #pdf_hzz4l_accept lnN 1.02 1.02 1.02 1.02 1.02 - - - + #QCDscale_ggH lnN 1.0750 - - - - - - - + #QCDscale_qqH lnN - 1.0020 - - - - - - + #QCDscale_VH lnN - - 1.0040 1.0155 - - - - + #QCDscale_ttH lnN - - - - 1.0655 - - - + #QCDscale_ggVV lnN - - - - - - 1.2435 - + #BRhiggs_hzz4l lnN 1.02 1.02 1.02 1.02 1.02 - - - + # unc_theory_ggH_hi = sqrt(0.072**2+0.075**2+0.02**2+0.02**2) + # unc_theory_ggH_lo = sqrt(0.078**2+0.069**2+0.02**2+0.02**2) + # unc_theory_XH_hi = sqrt(0.027**2+0.02**2+0.002**2+0.02**2) + # unc_theory_XH_lo = unc_theory_XH_hi + # unc_VBF = sqrt(0.027**2+0.02**2+0.002**2+0.02**2) + # unc_WH = sqrt(0.035**2+0.02**2+0.004**2+0.02**2) + # unc_ZH = sqrt(0.035**2+0.02**2+0.0155**2+0.02**2) + # unc_ttH = sqrt(0.078**2+0.02**2+0.0655**2+0.02**2) + + unc_acc = 0.02 + unc_br = 0.02 + + #unc_pdf_ggH_hi = 0.075 + unc_pdf_ggH_hi = 0.032 + unc_pdf_ggH_lo = 0.032 + unc_pdf_VBF = 0.021 + unc_pdf_WH = 0.023 + unc_pdf_ZH = 0.025 + unc_pdf_ttH = 0.081 + + #unc_qcd_ggH_hi = 0.072 + unc_qcd_ggH_hi = 0.039 + unc_qcd_ggH_lo = 0.039 + unc_qcd_VBF = 0.002 + unc_qcd_WH = 0.01 + unc_qcd_ZH = 0.031 + unc_qcd_ttH = 0.0655 + + nBins=len(obs_bins) + for obsBin in range(nBins-1): + # theory cross sections + ggH_powheg.append(0.0) + ggH_powheg_unc_hi.append(0.0) + ggH_powheg_unc_lo.append(0.0) + ggH_minloHJ.append(0.0) + ggH_minloHJ_unc_hi.append(0.0) + ggH_minloHJ_unc_lo.append(0.0) + # ggH_HRes.append(0.0) + # ggH_HRes_unc_hi.append(0.0) + # ggH_HRes_unc_lo.append(0.0) + # NNLO theory unc + ggH_powheg_NNLOunc_hi.append(0.0) + ggH_powheg_NNLOunc_lo.append(0.0) + ggH_minloHJ_NNLOunc_hi.append(0.0) + ggH_minloHJ_NNLOunc_lo.append(0.0) + # ggH_HRes_NNLOunc_hi.append(0.0) + # ggH_HRes_NNLOunc_lo.append(0.0) + # NLO theory unc + ggH_powheg_NLOunc_hi.append(0.0) + ggH_powheg_NLOunc_lo.append(0.0) + ggH_minloHJ_NLOunc_hi.append(0.0) + ggH_minloHJ_NLOunc_lo.append(0.0) + # XH + XH.append(0.0) + XH_unc.append(0.0) + # AC + if(acFlag): + ggH_AC.append(0.0) + ggH_AC_unc_hi.append(0.0) + ggH_AC_unc_lo.append(0.0) + ggH_AC_NNLOunc_hi.append(0.0) + ggH_AC_NNLOunc_lo.append(0.0) + ggH_AC_NLOunc_hi.append(0.0) + ggH_AC_NLOunc_lo.append(0.0) + XH_AC.append(0.0) + XH_AC_unc.append(0.0) + if(acFlagBis): + ggH_ACbis.append(0.0) + ggH_ACbis_unc_hi.append(0.0) + ggH_ACbis_unc_lo.append(0.0) + ggH_ACbis_NNLOunc_hi.append(0.0) + ggH_ACbis_NNLOunc_lo.append(0.0) + ggH_ACbis_NLOunc_hi.append(0.0) + ggH_ACbis_NLOunc_lo.append(0.0) + XH_ACbis.append(0.0) + XH_ACbis_unc.append(0.0) + # Data + data.append(0.0) + data_hi.append(0.0) + data_lo.append(0.0) + data_hi2.append(0.0) + data_lo2.append(0.0) + asimovdata.append(0.0) + # Systematic unc + modeldep_hi.append(0.0) + modeldep_lo.append(0.0) + systematics_hi.append(0.0) + systematics_lo.append(0.0) + systematics_hi2.append(0.0) + systematics_lo2.append(0.0) + data_hi_allunc.append(0.0) + data_lo_allunc.append(0.0) + stat_hi.append(0.0) + stat_lo.append(0.0) + + if chan == '4l': + for channel in ['4e','4mu']: + XH_fs = higgs_xs['VBF_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc['VBFH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + XH_fs += higgs_xs['WH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc['WH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + XH_fs += higgs_xs['ZH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc['ZH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + XH_fs += higgs_xs['ttH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc['ttH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + + XH[obsBin]+=XH_fs + #XH_unc[obsBin]+= unc_ttH*higgs_xs['ttH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc['ttH_powheg_JHUgen_125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + #XH_unc[obsBin]+= unc_VBF*higgs_xs['VBF_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc['VBF_powheg_JHUgen_125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + #XH_unc[obsBin]+= unc_WH*higgs_xs['WH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc['WH_powheg_JHUgen_125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + #XH_unc[obsBin]+= unc_ZH*higgs_xs['ZH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc['ZH_powheg_JHUgen_125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + + # branching ratio uncertainty + XH_unc_fs = (unc_br*XH_fs)**2 + # acceptance uncertainty + XH_unc_fs += (unc_acc*XH_fs)**2 + + # qcd scale + XH_qcdunc_fs = (unc_qcd_VBF*higgs_xs['VBF_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc['VBFH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + XH_qcdunc_fs += (unc_qcd_WH*higgs_xs['WH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc['WH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + XH_qcdunc_fs += (unc_qcd_ZH*higgs_xs['ZH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc['ZH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + XH_qcdunc_fs += (unc_qcd_ttH*higgs_xs['ttH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc['ttH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + XH_unc_fs += XH_qcdunc_fs + + # pdf + XH_qqpdfunc_fs = (unc_pdf_VBF*higgs_xs['VBF_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc['VBFH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + +unc_pdf_WH*higgs_xs['WH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc['WH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + +unc_pdf_ZH*higgs_xs['ZH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc['ZH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + XH_unc_fs += XH_qqpdfunc_fs + + # add pdf uncertainty for ttH to total XH uncertainty + XH_unc_fs += (unc_pdf_ttH*higgs_xs['ttH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc['ttH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + + # total XH uncertainty + XH_unc[obsBin]+=sqrt(XH_unc_fs) + + # AC + if(acFlag): + XH_AC_fs = higgs_xs['VBF_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*accCorrFact['VBFH125_'+fState+'_genbin'+str(obsBin)]*acc_AC['ggH'+acSample+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + XH_AC_fs += higgs_xs['WH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*accCorrFact['WH125_'+fState+'_genbin'+str(obsBin)]*acc_AC['ggH'+acSample+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + XH_AC_fs += higgs_xs['ZH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*accCorrFact['ZH125_'+fState+'_genbin'+str(obsBin)]*acc_AC['ggH'+acSample+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + XH_AC_fs += higgs_xs['ttH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*accCorrFact['ttH125_'+fState+'_genbin'+str(obsBin)]*acc_AC['ggH'+acSample+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + + XH_AC[obsBin]+=XH_AC_fs + + # branching ratio uncertainty + XH_AC_unc_fs = (unc_br*XH_AC_fs)**2 + # acceptance uncertainty + XH_AC_unc_fs += (unc_acc*XH_AC_fs)**2 + + XH_AC_qcdunc_fs = (unc_qcd_VBF*higgs_xs['VBF_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*accCorrFact['VBFH125_'+fState+'_genbin'+str(obsBin)]*acc_AC['ggH'+acSample+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + XH_AC_qcdunc_fs += (unc_qcd_WH*higgs_xs['WH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*accCorrFact['WH125_'+fState+'_genbin'+str(obsBin)]*acc_AC['ggH'+acSample+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + XH_AC_qcdunc_fs += (unc_qcd_ZH*higgs_xs['ZH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*accCorrFact['ZH125_'+fState+'_genbin'+str(obsBin)]*acc_AC['ggH'+acSample+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + XH_AC_qcdunc_fs += (unc_qcd_ttH*higgs_xs['ttH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*accCorrFact['ttH125_'+fState+'_genbin'+str(obsBin)]*acc_AC['ggH'+acSample+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + XH_AC_unc_fs += XH_qcdunc_fs + + # pdf + XH_AC_qqpdfunc_fs = (unc_pdf_VBF*higgs_xs['VBF_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]**accCorrFact['VBFH125_'+fState+'_genbin'+str(obsBin)]*acc_AC['ggH'+acSample+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + +unc_pdf_WH*higgs_xs['WH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*accCorrFact['WH125_'+fState+'_genbin'+str(obsBin)]*acc_AC['ggH'+acSample+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + +unc_pdf_ZH*higgs_xs['ZH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*accCorrFact['ZH125_'+fState+'_genbin'+str(obsBin)]*acc_AC['ggH'+acSample+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + XH_AC_unc_fs += XH_qqpdfunc_fs + + # add pdf uncertainty for ttH to total XH uncertainty + XH_AC_unc_fs += (unc_pdf_ttH*higgs_xs['ttH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*accCorrFact['ttH125_'+fState+'_genbin'+str(obsBin)]*acc_AC['ggH'+acSample+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + + # total XH uncertainty + XH_AC_unc[obsBin]+=sqrt(XH_AC_unc_fs) + + if(acFlagBis): + XH_ACbis_fs = higgs_xs['VBF_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*accCorrFact['VBFH125_'+fState+'_genbin'+str(obsBin)]*acc_ACbis['ggH'+acSampleBis+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + XH_ACbis_fs += higgs_xs['WH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*accCorrFact['WH125_'+fState+'_genbin'+str(obsBin)]*acc_ACbis['ggH'+acSampleBis+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + XH_ACbis_fs += higgs_xs['ZH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*accCorrFact['ZH125_'+fState+'_genbin'+str(obsBin)]*acc_ACbis['ggH'+acSampleBis+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + XH_ACbis_fs += higgs_xs['ttH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*accCorrFact['ttH125_'+fState+'_genbin'+str(obsBin)]*acc_ACbis['ggH'+acSampleBis+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + + XH_ACbis[obsBin]+=XH_ACbis_fs + + # branching ratio uncertainty + XH_ACbis_unc_fs = (unc_br*XH_ACbis_fs)**2 + # acceptance uncertainty + XH_ACbis_unc_fs += (unc_acc*XH_ACbis_fs)**2 + + XH_ACbis_qcdunc_fs = (unc_qcd_VBF*higgs_xs['VBF_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*accCorrFact['VBFH125_'+fState+'_genbin'+str(obsBin)]*acc_ACbis['ggH'+acSampleBis+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + XH_ACbis_qcdunc_fs += (unc_qcd_WH*higgs_xs['WH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*accCorrFact['WH125_'+fState+'_genbin'+str(obsBin)]*acc_ACbis['ggH'+acSampleBis+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + XH_ACbis_qcdunc_fs += (unc_qcd_ZH*higgs_xs['ZH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*accCorrFact['ZH125_'+fState+'_genbin'+str(obsBin)]*acc_ACbis['ggH'+acSampleBis+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + XH_ACbis_qcdunc_fs += (unc_qcd_ttH*higgs_xs['ttH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*accCorrFact['ttH125_'+fState+'_genbin'+str(obsBin)]*acc_ACbis['ggH'+acSampleBis+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + XH_ACbis_unc_fs += XH_qcdunc_fs + + # pdf + XH_ACbis_qqpdfunc_fs = (unc_pdf_VBF*higgs_xs['VBF_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]**accCorrFact['VBFH125_'+fState+'_genbin'+str(obsBin)]*acc_ACbis['ggH'+acSampleBis+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + +unc_pdf_WH*higgs_xs['WH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*accCorrFact['WH125_'+fState+'_genbin'+str(obsBin)]*acc_ACbis['ggH'+acSampleBis+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + +unc_pdf_ZH*higgs_xs['ZH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*accCorrFact['ZH125_'+fState+'_genbin'+str(obsBin)]*acc_ACbis['ggH'+acSampleBis+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + XH_ACbis_unc_fs += XH_qqpdfunc_fs + + # add pdf uncertainty for ttH to total XH uncertainty + XH_ACbis_unc_fs += (unc_pdf_ttH*higgs_xs['ttH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*accCorrFact['ttH125_'+fState+'_genbin'+str(obsBin)]*acc_ACbis['ggH'+acSampleBis+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + + # total XH uncertainty + XH_ACbis_unc[obsBin]+=sqrt(XH_ACbis_unc_fs) + + + # ggH cross sections + ggH_xsBR = higgs_xs['ggH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel] + #print "ggH_xsBR",ggH_xsBR + #print "ggH_xsBR_emutau",higgs_xs['ggH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_emutau'] + + ggH_powheg[obsBin]+=ggH_xsBR*acc['ggH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + #ggH_minloHJ[obsBin]+=ggH_xsBR*acc_ggH_powheg['ggH_powheg_JHUgen_125_'+channel+'_'+obsName+'_genbin'+str(obsBin)] + ggH_minloHJ[obsBin]+=ggH_xsBR*acc_NNLOPS['ggH125_NNLOPS_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + # AC + if(acFlag): + ggH_AC[obsBin]+=ggH_xsBR*acc_AC['ggH'+acSample+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + if(acFlagBis): + ggH_ACbis[obsBin]+=ggH_xsBR*acc_ACbis['ggH'+acSampleBis+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + + # for total uncertainty, correlate br and acc uncertainties across all channels (XH+ggH) + total_NNLOunc_fs_powheg_hi = (unc_br*(XH_fs+ggH_xsBR*acc['ggH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)]))**2 + total_NNLOunc_fs_powheg_lo = (unc_br*(XH_fs+ggH_xsBR*acc['ggH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)]))**2 + total_NNLOunc_fs_powheg_hi += (unc_acc*(XH_fs+ggH_xsBR*acc['ggH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)]))**2 + total_NNLOunc_fs_powheg_lo += (unc_acc*(XH_fs+ggH_xsBR*acc['ggH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)]))**2 + + total_NNLOunc_fs_minloHJ_hi = (unc_br*(XH_fs+ggH_xsBR*acc_NNLOPS['ggH125_NNLOPS_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)]))**2 + total_NNLOunc_fs_minloHJ_lo = (unc_br*(XH_fs+ggH_xsBR*acc_NNLOPS['ggH125_NNLOPS_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)]))**2 + total_NNLOunc_fs_minloHJ_hi += (unc_acc*(XH_fs+ggH_xsBR*acc_NNLOPS['ggH125_NNLOPS_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)]))**2 + total_NNLOunc_fs_minloHJ_lo += (unc_acc*(XH_fs+ggH_xsBR*acc_NNLOPS['ggH125_NNLOPS_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)]))**2 + + # NLO and NNLO are the same at this point + total_NLOunc_fs_powheg_hi = total_NNLOunc_fs_powheg_hi + total_NLOunc_fs_powheg_lo = total_NNLOunc_fs_powheg_lo + if acFlag: + total_NLOunc_fs_AC_hi = (unc_br*(XH_AC_fs+ggH_xsBR*acc_AC['ggH'+acSample+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)]))**2 + total_NLOunc_fs_AC_lo = (unc_br*(XH_AC_fs+ggH_xsBR*acc_AC['ggH'+acSample+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)]))**2 + total_NLOunc_fs_AC_hi += (unc_acc*(XH_AC_fs+ggH_xsBR*acc_AC['ggH'+acSample+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)]))**2 + total_NLOunc_fs_AC_lo += (unc_acc*(XH_AC_fs+ggH_xsBR*acc_AC['ggH'+acSample+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)]))**2 + if acFlagBis: + total_NLOunc_fs_ACbis_hi = (unc_br*(XH_ACbis_fs+ggH_xsBR*acc_ACbis['ggH'+acSampleBis+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)]))**2 + total_NLOunc_fs_ACbis_lo = (unc_br*(XH_ACbis_fs+ggH_xsBR*acc_ACbis['ggH'+acSampleBis+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)]))**2 + total_NLOunc_fs_ACbis_hi += (unc_acc*(XH_ACbis_fs+ggH_xsBR*acc_ACbis['ggH'+acSampleBis+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)]))**2 + total_NLOunc_fs_ACbis_lo += (unc_acc*(XH_ACbis_fs+ggH_xsBR*acc_ACbis['ggH'+acSampleBis+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)]))**2 + #total_NLOunc_fs_powheg_hi = 0.0 + #total_NLOunc_fs_powheg_lo = 0.0 + + total_NLOunc_fs_minloHJ_hi = total_NNLOunc_fs_minloHJ_hi + total_NLOunc_fs_minloHJ_lo = total_NNLOunc_fs_minloHJ_lo + + + # add ggH qcd uncertainties (uncorrelated with anything else) + #NNLO + + total_NNLOunc_fs_powheg_hi += XH_qcdunc_fs + total_NNLOunc_fs_powheg_lo += XH_qcdunc_fs + total_NNLOunc_fs_powheg_hi += (unc_qcd_ggH_hi*ggH_xsBR*acc['ggH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + total_NNLOunc_fs_powheg_lo += (unc_qcd_ggH_lo*ggH_xsBR*acc['ggH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + + total_NNLOunc_fs_minloHJ_hi += XH_qcdunc_fs + total_NNLOunc_fs_minloHJ_lo += XH_qcdunc_fs + if (obsName=="mass4l"): + total_NNLOunc_fs_minloHJ_hi += (unc_qcd_ggH_hi + *ggH_xsBR*acc_NNLOPS['ggH125_NNLOPS_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + total_NNLOunc_fs_minloHJ_lo += (unc_qcd_ggH_lo + *ggH_xsBR*acc_NNLOPS['ggH125_NNLOPS_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + else: + total_NNLOunc_fs_minloHJ_hi += (qcdunc_ggH_nnlops["ggH125_NNLOPS_"+channel+"_"+obsName.replace('_reco','_gen')+"_genbin"+str(obsBin)]['uncerUp'] + *ggH_xsBR*acc_NNLOPS['ggH125_NNLOPS_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + total_NNLOunc_fs_minloHJ_lo += (qcdunc_ggH_nnlops["ggH125_NNLOPS_"+channel+"_"+obsName.replace('_reco','_gen')+"_genbin"+str(obsBin)]['uncerDn'] + *ggH_xsBR*acc_NNLOPS['ggH125_NNLOPS_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + + #NLO + total_NLOunc_fs_powheg_hi += XH_qcdunc_fs + total_NLOunc_fs_powheg_lo += XH_qcdunc_fs + total_NLOunc_fs_powheg_hi += (qcdunc_ggH_powheg["ggH125_"+channel+"_"+obsName.replace('_reco','_gen')+"_genbin"+str(obsBin)]['uncerUp'] + *ggH_xsBR*acc['ggH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + total_NLOunc_fs_powheg_lo += (qcdunc_ggH_powheg["ggH125_"+channel+"_"+obsName.replace('_reco','_gen')+"_genbin"+str(obsBin)]['uncerDn'] + *ggH_xsBR*acc['ggH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + + if acFlag: + total_NLOunc_fs_AC_hi += XH_AC_qcdunc_fs + total_NLOunc_fs_AC_hi += XH_AC_qcdunc_fs + total_NLOunc_fs_AC_hi += (qcdunc_ggH_powheg["ggH125_"+channel+"_"+obsName.replace('_reco','_gen')+"_genbin"+str(obsBin)]['uncerUp'] + *ggH_xsBR*acc_AC['ggH'+acSample+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + total_NLOunc_fs_AC_lo += (qcdunc_ggH_powheg["ggH125_"+channel+"_"+obsName.replace('_reco','_gen')+"_genbin"+str(obsBin)]['uncerDn'] + *ggH_xsBR*acc_AC['ggH'+acSample+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + + if acFlagBis: + total_NLOunc_fs_ACbis_hi += XH_ACbis_qcdunc_fs + total_NLOunc_fs_ACbis_hi += XH_ACbis_qcdunc_fs + total_NLOunc_fs_ACbis_hi += (qcdunc_ggH_powheg["ggH125_"+channel+"_"+obsName.replace('_reco','_gen')+"_genbin"+str(obsBin)]['uncerUp'] + *ggH_xsBR*acc_ACbis['ggH'+acSampleBis+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + total_NLOunc_fs_ACbis_lo += (qcdunc_ggH_powheg["ggH125_"+channel+"_"+obsName.replace('_reco','_gen')+"_genbin"+str(obsBin)]['uncerDn'] + *ggH_xsBR*acc_ACbis['ggH'+acSampleBis+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + + + print channel,total_NLOunc_fs_powheg_hi + + total_NLOunc_fs_minloHJ_hi += XH_qcdunc_fs + total_NLOunc_fs_minloHJ_lo += XH_qcdunc_fs + total_NLOunc_fs_minloHJ_hi += (qcdunc_ggH_nnlops["ggH125_NNLOPS_"+channel+"_"+obsName.replace('_reco','_gen')+"_genbin"+str(obsBin)]['uncerUp'] + *ggH_xsBR*acc_NNLOPS['ggH125_NNLOPS_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + total_NLOunc_fs_minloHJ_lo += (qcdunc_ggH_nnlops["ggH125_NNLOPS_"+channel+"_"+obsName.replace('_reco','_gen')+"_genbin"+str(obsBin)]['uncerDn'] + *ggH_xsBR*acc_NNLOPS['ggH125_NNLOPS_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + + # add pdf unc, anti correlate ggH and ttH + #NNLO + if (obsName=="mass4l"): + obsUnc_pdf_ggH_hi = unc_pdf_ggH_hi + obsUnc_pdf_ggH_lo = unc_pdf_ggH_lo + else: + obsUnc_pdf_ggH_hi = pdfunc_ggH_powheg["ggH125_"+channel+"_"+obsName.replace('_reco','_gen')+"_genbin"+str(obsBin)]['uncerUp'] + obsUnc_pdf_ggH_lo = pdfunc_ggH_powheg["ggH125_"+channel+"_"+obsName.replace('_reco','_gen')+"_genbin"+str(obsBin)]['uncerUp'] + + total_NNLOunc_fs_powheg_hi += XH_qqpdfunc_fs + total_NNLOunc_fs_powheg_lo += XH_qqpdfunc_fs + total_NNLOunc_fs_powheg_hi += (obsUnc_pdf_ggH_hi*ggH_xsBR*acc['ggH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + -unc_pdf_ttH*higgs_xs['ttH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc['ttH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + total_NNLOunc_fs_powheg_lo += (obsUnc_pdf_ggH_lo*ggH_xsBR*acc['ggH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + -unc_pdf_ttH*higgs_xs['ttH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc['ttH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + + + total_NNLOunc_fs_minloHJ_hi += XH_qqpdfunc_fs + total_NNLOunc_fs_minloHJ_lo += XH_qqpdfunc_fs + total_NNLOunc_fs_minloHJ_hi += (obsUnc_pdf_ggH_hi*ggH_xsBR*acc_NNLOPS['ggH125_NNLOPS_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + -unc_pdf_ttH*higgs_xs['ttH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc['ttH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + total_NNLOunc_fs_minloHJ_lo += (obsUnc_pdf_ggH_lo*ggH_xsBR*acc_NNLOPS['ggH125_NNLOPS_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + -unc_pdf_ttH*higgs_xs['ttH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc['ttH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + + #NLO + total_NLOunc_fs_powheg_hi += XH_qqpdfunc_fs + total_NLOunc_fs_powheg_lo += XH_qqpdfunc_fs + total_NLOunc_fs_powheg_hi += (pdfunc_ggH_powheg["ggH125_"+channel+"_"+obsName.replace('_reco','_gen')+"_genbin"+str(obsBin)]['uncerUp'] + *ggH_xsBR*acc['ggH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + -unc_pdf_ttH*higgs_xs['ttH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc['ttH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + total_NLOunc_fs_powheg_lo += (pdfunc_ggH_powheg["ggH125_"+channel+"_"+obsName.replace('_reco','_gen')+"_genbin"+str(obsBin)]['uncerDn'] + *ggH_xsBR*acc['ggH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + -unc_pdf_ttH*higgs_xs['ttH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc['ttH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + if acFlag: + total_NLOunc_fs_AC_hi += XH_AC_qqpdfunc_fs + total_NLOunc_fs_AC_lo += XH_AC_qqpdfunc_fs + total_NLOunc_fs_AC_hi += (pdfunc_ggH_powheg["ggH125_"+channel+"_"+obsName.replace('_reco','_gen')+"_genbin"+str(obsBin)]['uncerUp'] + *ggH_xsBR*acc_AC['ggH'+acSample+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + -unc_pdf_ttH*higgs_xs['ttH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc_AC['ggH'+acSample+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + total_NLOunc_fs_AC_lo += (pdfunc_ggH_powheg["ggH125_"+channel+"_"+obsName.replace('_reco','_gen')+"_genbin"+str(obsBin)]['uncerDn'] + *ggH_xsBR*acc_AC['ggH'+acSample+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + -unc_pdf_ttH*higgs_xs['ttH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc_AC['ggH'+acSample+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + if acFlagBis: + total_NLOunc_fs_ACbis_hi += XH_ACbis_qqpdfunc_fs + total_NLOunc_fs_ACbis_lo += XH_ACbis_qqpdfunc_fs + total_NLOunc_fs_ACbis_hi += (pdfunc_ggH_powheg["ggH125_"+channel+"_"+obsName.replace('_reco','_gen')+"_genbin"+str(obsBin)]['uncerUp'] + *ggH_xsBR*acc_ACbis['ggH'+acSampleBis+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + -unc_pdf_ttH*higgs_xs['ttH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc_ACbis['ggH'+acSampleBis+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + total_NLOunc_fs_ACbis_lo += (pdfunc_ggH_powheg["ggH125_"+channel+"_"+obsName.replace('_reco','_gen')+"_genbin"+str(obsBin)]['uncerDn'] + *ggH_xsBR*acc_ACbis['ggH'+acSampleBis+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + -unc_pdf_ttH*higgs_xs['ttH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc_ACbis['ggH'+acSampleBis+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + + + total_NLOunc_fs_minloHJ_hi += XH_qqpdfunc_fs + total_NLOunc_fs_minloHJ_lo += XH_qqpdfunc_fs + total_NLOunc_fs_minloHJ_hi += (pdfunc_ggH_nnlops["ggH125_NNLOPS_"+channel+"_"+obsName.replace('_reco','_gen')+"_genbin"+str(obsBin)]['uncerUp'] + *ggH_xsBR*acc_NNLOPS['ggH125_NNLOPS_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + -unc_pdf_ttH*higgs_xs['ttH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc['ttH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + total_NLOunc_fs_minloHJ_lo += (pdfunc_ggH_nnlops["ggH125_NNLOPS_"+channel+"_"+obsName.replace('_reco','_gen')+"_genbin"+str(obsBin)]['uncerDn'] + *ggH_xsBR*acc_NNLOPS['ggH125_NNLOPS_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + -unc_pdf_ttH*higgs_xs['ttH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc['ttH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + + # finally total uncertainty (different final states are correlated) + # NNLO + ggH_powheg_NNLOunc_hi[obsBin]+=sqrt(total_NNLOunc_fs_powheg_hi) + ggH_powheg_NNLOunc_lo[obsBin]+=sqrt(total_NNLOunc_fs_powheg_lo) + ggH_minloHJ_NNLOunc_hi[obsBin]+=sqrt(total_NNLOunc_fs_minloHJ_hi) + ggH_minloHJ_NNLOunc_lo[obsBin]+=sqrt(total_NNLOunc_fs_minloHJ_lo) + # NLO + ggH_powheg_NLOunc_hi[obsBin]+=sqrt(total_NLOunc_fs_powheg_hi) + ggH_powheg_NLOunc_lo[obsBin]+=sqrt(total_NLOunc_fs_powheg_lo) + ggH_minloHJ_NLOunc_hi[obsBin]+=sqrt(total_NLOunc_fs_minloHJ_hi) + ggH_minloHJ_NLOunc_lo[obsBin]+=sqrt(total_NLOunc_fs_minloHJ_lo) + if(acFlag): + ggH_AC_NLOunc_hi[obsBin]+=sqrt(total_NLOunc_fs_AC_hi) + ggH_AC_NLOunc_lo[obsBin]+=sqrt(total_NLOunc_fs_AC_lo) + if(acFlagBis): + ggH_ACbis_NLOunc_hi[obsBin]+=sqrt(total_NLOunc_fs_ACbis_hi) + ggH_ACbis_NLOunc_lo[obsBin]+=sqrt(total_NLOunc_fs_ACbis_lo) + + if chan == '2e2mu': + for channel in ['2e2mu']: + XH_fs = higgs_xs['VBF_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc['VBFH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + XH_fs += higgs_xs['WH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc['WH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + XH_fs += higgs_xs['ZH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc['ZH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + XH_fs += higgs_xs['ttH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc['ttH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + + XH[obsBin]+=XH_fs + #XH_unc[obsBin]+= unc_ttH*higgs_xs['ttH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc['ttH_powheg_JHUgen_125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + #XH_unc[obsBin]+= unc_VBF*higgs_xs['VBF_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc['VBF_powheg_JHUgen_125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + #XH_unc[obsBin]+= unc_WH*higgs_xs['WH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc['WH_powheg_JHUgen_125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + #XH_unc[obsBin]+= unc_ZH*higgs_xs['ZH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc['ZH_powheg_JHUgen_125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + + # branching ratio uncertainty + XH_unc_fs = (unc_br*XH_fs)**2 + # acceptance uncertainty + XH_unc_fs += (unc_acc*XH_fs)**2 + + # qcd scale + XH_qcdunc_fs = (unc_qcd_VBF*higgs_xs['VBF_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc['VBFH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + XH_qcdunc_fs += (unc_qcd_WH*higgs_xs['WH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc['WH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + XH_qcdunc_fs += (unc_qcd_ZH*higgs_xs['ZH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc['ZH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + XH_qcdunc_fs += (unc_qcd_ttH*higgs_xs['ttH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc['ttH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + XH_unc_fs += XH_qcdunc_fs + + # pdf + XH_qqpdfunc_fs = (unc_pdf_VBF*higgs_xs['VBF_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc['VBFH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + +unc_pdf_WH*higgs_xs['WH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc['WH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + +unc_pdf_ZH*higgs_xs['ZH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc['ZH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + XH_unc_fs += XH_qqpdfunc_fs + + # add pdf uncertainty for ttH to total XH uncertainty + XH_unc_fs += (unc_pdf_ttH*higgs_xs['ttH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc['ttH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + + # total XH uncertainty + XH_unc[obsBin]+=sqrt(XH_unc_fs) + + # AC + if(acFlag): + XH_AC_fs = higgs_xs['VBF_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*accCorrFact['VBFH125_'+fState+'_genbin'+str(obsBin)]*acc_AC['ggH'+acSample+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + XH_AC_fs += higgs_xs['WH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*accCorrFact['WH125_'+fState+'_genbin'+str(obsBin)]*acc_AC['ggH'+acSample+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + XH_AC_fs += higgs_xs['ZH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*accCorrFact['ZH125_'+fState+'_genbin'+str(obsBin)]*acc_AC['ggH'+acSample+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + XH_AC_fs += higgs_xs['ttH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*accCorrFact['ttH125_'+fState+'_genbin'+str(obsBin)]*acc_AC['ggH'+acSample+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + + XH_AC[obsBin]+=XH_AC_fs + + # branching ratio uncertainty + XH_AC_unc_fs = (unc_br*XH_AC_fs)**2 + # acceptance uncertainty + XH_AC_unc_fs += (unc_acc*XH_AC_fs)**2 + + XH_AC_qcdunc_fs = (unc_qcd_VBF*higgs_xs['VBF_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*accCorrFact['VBFH125_'+fState+'_genbin'+str(obsBin)]*acc_AC['ggH'+acSample+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + XH_AC_qcdunc_fs += (unc_qcd_WH*higgs_xs['WH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*accCorrFact['WH125_'+fState+'_genbin'+str(obsBin)]*acc_AC['ggH'+acSample+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + XH_AC_qcdunc_fs += (unc_qcd_ZH*higgs_xs['ZH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*accCorrFact['ZH125_'+fState+'_genbin'+str(obsBin)]*acc_AC['ggH'+acSample+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + XH_AC_qcdunc_fs += (unc_qcd_ttH*higgs_xs['ttH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*accCorrFact['ttH125_'+fState+'_genbin'+str(obsBin)]*acc_AC['ggH'+acSample+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + XH_AC_unc_fs += XH_qcdunc_fs + + # pdf + XH_AC_qqpdfunc_fs = (unc_pdf_VBF*higgs_xs['VBF_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]**accCorrFact['VBFH125_'+fState+'_genbin'+str(obsBin)]*acc_AC['ggH'+acSample+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + +unc_pdf_WH*higgs_xs['WH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*accCorrFact['WH125_'+fState+'_genbin'+str(obsBin)]*acc_AC['ggH'+acSample+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + +unc_pdf_ZH*higgs_xs['ZH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*accCorrFact['ZH125_'+fState+'_genbin'+str(obsBin)]*acc_AC['ggH'+acSample+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + XH_AC_unc_fs += XH_qqpdfunc_fs + + # add pdf uncertainty for ttH to total XH uncertainty + XH_AC_unc_fs += (unc_pdf_ttH*higgs_xs['ttH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*accCorrFact['ttH125_'+fState+'_genbin'+str(obsBin)]*acc_AC['ggH'+acSample+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + + # total XH uncertainty + XH_AC_unc[obsBin]+=sqrt(XH_AC_unc_fs) + + if(acFlagBis): + XH_ACbis_fs = higgs_xs['VBF_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*accCorrFact['VBFH125_'+fState+'_genbin'+str(obsBin)]*acc_ACbis['ggH'+acSampleBis+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + XH_ACbis_fs += higgs_xs['WH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*accCorrFact['WH125_'+fState+'_genbin'+str(obsBin)]*acc_ACbis['ggH'+acSampleBis+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + XH_ACbis_fs += higgs_xs['ZH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*accCorrFact['ZH125_'+fState+'_genbin'+str(obsBin)]*acc_ACbis['ggH'+acSampleBis+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + XH_ACbis_fs += higgs_xs['ttH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*accCorrFact['ttH125_'+fState+'_genbin'+str(obsBin)]*acc_ACbis['ggH'+acSampleBis+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + + XH_ACbis[obsBin]+=XH_ACbis_fs + + # branching ratio uncertainty + XH_ACbis_unc_fs = (unc_br*XH_ACbis_fs)**2 + # acceptance uncertainty + XH_ACbis_unc_fs += (unc_acc*XH_ACbis_fs)**2 + + XH_ACbis_qcdunc_fs = (unc_qcd_VBF*higgs_xs['VBF_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*accCorrFact['VBFH125_'+fState+'_genbin'+str(obsBin)]*acc_ACbis['ggH'+acSampleBis+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + XH_ACbis_qcdunc_fs += (unc_qcd_WH*higgs_xs['WH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*accCorrFact['WH125_'+fState+'_genbin'+str(obsBin)]*acc_ACbis['ggH'+acSampleBis+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + XH_ACbis_qcdunc_fs += (unc_qcd_ZH*higgs_xs['ZH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*accCorrFact['ZH125_'+fState+'_genbin'+str(obsBin)]*acc_ACbis['ggH'+acSampleBis+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + XH_ACbis_qcdunc_fs += (unc_qcd_ttH*higgs_xs['ttH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*accCorrFact['ttH125_'+fState+'_genbin'+str(obsBin)]*acc_ACbis['ggH'+acSampleBis+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + XH_ACbis_unc_fs += XH_qcdunc_fs + + # pdf + XH_ACbis_qqpdfunc_fs = (unc_pdf_VBF*higgs_xs['VBF_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]**accCorrFact['VBFH125_'+fState+'_genbin'+str(obsBin)]*acc_ACbis['ggH'+acSampleBis+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + +unc_pdf_WH*higgs_xs['WH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*accCorrFact['WH125_'+fState+'_genbin'+str(obsBin)]*acc_ACbis['ggH'+acSampleBis+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + +unc_pdf_ZH*higgs_xs['ZH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*accCorrFact['ZH125_'+fState+'_genbin'+str(obsBin)]*acc_ACbis['ggH'+acSampleBis+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + XH_ACbis_unc_fs += XH_qqpdfunc_fs + + # add pdf uncertainty for ttH to total XH uncertainty + XH_ACbis_unc_fs += (unc_pdf_ttH*higgs_xs['ttH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*accCorrFact['ttH125_'+fState+'_genbin'+str(obsBin)]*acc_ACbis['ggH'+acSampleBis+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + + # total XH uncertainty + XH_ACbis_unc[obsBin]+=sqrt(XH_ACbis_unc_fs) + + + # ggH cross sections + ggH_xsBR = higgs_xs['ggH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel] + #print "ggH_xsBR",ggH_xsBR + #print "ggH_xsBR_emutau",higgs_xs['ggH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_emutau'] + + ggH_powheg[obsBin]+=ggH_xsBR*acc['ggH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + #ggH_minloHJ[obsBin]+=ggH_xsBR*acc_ggH_powheg['ggH_powheg_JHUgen_125_'+channel+'_'+obsName+'_genbin'+str(obsBin)] + ggH_minloHJ[obsBin]+=ggH_xsBR*acc_NNLOPS['ggH125_NNLOPS_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + # AC + if(acFlag): + ggH_AC[obsBin]+=ggH_xsBR*acc_AC['ggH'+acSample+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + if(acFlagBis): + ggH_ACbis[obsBin]+=ggH_xsBR*acc_ACbis['ggH'+acSampleBis+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + + # for total uncertainty, correlate br and acc uncertainties across all channels (XH+ggH) + total_NNLOunc_fs_powheg_hi = (unc_br*(XH_fs+ggH_xsBR*acc['ggH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)]))**2 + total_NNLOunc_fs_powheg_lo = (unc_br*(XH_fs+ggH_xsBR*acc['ggH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)]))**2 + total_NNLOunc_fs_powheg_hi += (unc_acc*(XH_fs+ggH_xsBR*acc['ggH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)]))**2 + total_NNLOunc_fs_powheg_lo += (unc_acc*(XH_fs+ggH_xsBR*acc['ggH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)]))**2 + + total_NNLOunc_fs_minloHJ_hi = (unc_br*(XH_fs+ggH_xsBR*acc_NNLOPS['ggH125_NNLOPS_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)]))**2 + total_NNLOunc_fs_minloHJ_lo = (unc_br*(XH_fs+ggH_xsBR*acc_NNLOPS['ggH125_NNLOPS_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)]))**2 + total_NNLOunc_fs_minloHJ_hi += (unc_acc*(XH_fs+ggH_xsBR*acc_NNLOPS['ggH125_NNLOPS_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)]))**2 + total_NNLOunc_fs_minloHJ_lo += (unc_acc*(XH_fs+ggH_xsBR*acc_NNLOPS['ggH125_NNLOPS_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)]))**2 + + # NLO and NNLO are the same at this point + total_NLOunc_fs_powheg_hi = total_NNLOunc_fs_powheg_hi + total_NLOunc_fs_powheg_lo = total_NNLOunc_fs_powheg_lo + if acFlag: + total_NLOunc_fs_AC_hi = (unc_br*(XH_AC_fs+ggH_xsBR*acc_AC['ggH'+acSample+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)]))**2 + total_NLOunc_fs_AC_lo = (unc_br*(XH_AC_fs+ggH_xsBR*acc_AC['ggH'+acSample+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)]))**2 + total_NLOunc_fs_AC_hi += (unc_acc*(XH_AC_fs+ggH_xsBR*acc_AC['ggH'+acSample+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)]))**2 + total_NLOunc_fs_AC_lo += (unc_acc*(XH_AC_fs+ggH_xsBR*acc_AC['ggH'+acSample+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)]))**2 + if acFlagBis: + total_NLOunc_fs_ACbis_hi = (unc_br*(XH_ACbis_fs+ggH_xsBR*acc_ACbis['ggH'+acSampleBis+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)]))**2 + total_NLOunc_fs_ACbis_lo = (unc_br*(XH_ACbis_fs+ggH_xsBR*acc_ACbis['ggH'+acSampleBis+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)]))**2 + total_NLOunc_fs_ACbis_hi += (unc_acc*(XH_ACbis_fs+ggH_xsBR*acc_ACbis['ggH'+acSampleBis+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)]))**2 + total_NLOunc_fs_ACbis_lo += (unc_acc*(XH_ACbis_fs+ggH_xsBR*acc_ACbis['ggH'+acSampleBis+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)]))**2 + #total_NLOunc_fs_powheg_hi = 0.0 + #total_NLOunc_fs_powheg_lo = 0.0 + + total_NLOunc_fs_minloHJ_hi = total_NNLOunc_fs_minloHJ_hi + total_NLOunc_fs_minloHJ_lo = total_NNLOunc_fs_minloHJ_lo + + + # add ggH qcd uncertainties (uncorrelated with anything else) + #NNLO + + total_NNLOunc_fs_powheg_hi += XH_qcdunc_fs + total_NNLOunc_fs_powheg_lo += XH_qcdunc_fs + total_NNLOunc_fs_powheg_hi += (unc_qcd_ggH_hi*ggH_xsBR*acc['ggH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + total_NNLOunc_fs_powheg_lo += (unc_qcd_ggH_lo*ggH_xsBR*acc['ggH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + + total_NNLOunc_fs_minloHJ_hi += XH_qcdunc_fs + total_NNLOunc_fs_minloHJ_lo += XH_qcdunc_fs + if (obsName=="mass4l"): + total_NNLOunc_fs_minloHJ_hi += (unc_qcd_ggH_hi + *ggH_xsBR*acc_NNLOPS['ggH125_NNLOPS_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + total_NNLOunc_fs_minloHJ_lo += (unc_qcd_ggH_lo + *ggH_xsBR*acc_NNLOPS['ggH125_NNLOPS_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + else: + total_NNLOunc_fs_minloHJ_hi += (qcdunc_ggH_nnlops["ggH125_NNLOPS_"+channel+"_"+obsName.replace('_reco','_gen')+"_genbin"+str(obsBin)]['uncerUp'] + *ggH_xsBR*acc_NNLOPS['ggH125_NNLOPS_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + total_NNLOunc_fs_minloHJ_lo += (qcdunc_ggH_nnlops["ggH125_NNLOPS_"+channel+"_"+obsName.replace('_reco','_gen')+"_genbin"+str(obsBin)]['uncerDn'] + *ggH_xsBR*acc_NNLOPS['ggH125_NNLOPS_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + + #NLO + total_NLOunc_fs_powheg_hi += XH_qcdunc_fs + total_NLOunc_fs_powheg_lo += XH_qcdunc_fs + total_NLOunc_fs_powheg_hi += (qcdunc_ggH_powheg["ggH125_"+channel+"_"+obsName.replace('_reco','_gen')+"_genbin"+str(obsBin)]['uncerUp'] + *ggH_xsBR*acc['ggH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + total_NLOunc_fs_powheg_lo += (qcdunc_ggH_powheg["ggH125_"+channel+"_"+obsName.replace('_reco','_gen')+"_genbin"+str(obsBin)]['uncerDn'] + *ggH_xsBR*acc['ggH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + + if acFlag: + total_NLOunc_fs_AC_hi += XH_AC_qcdunc_fs + total_NLOunc_fs_AC_hi += XH_AC_qcdunc_fs + total_NLOunc_fs_AC_hi += (qcdunc_ggH_powheg["ggH125_"+channel+"_"+obsName.replace('_reco','_gen')+"_genbin"+str(obsBin)]['uncerUp'] + *ggH_xsBR*acc_AC['ggH'+acSample+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + total_NLOunc_fs_AC_lo += (qcdunc_ggH_powheg["ggH125_"+channel+"_"+obsName.replace('_reco','_gen')+"_genbin"+str(obsBin)]['uncerDn'] + *ggH_xsBR*acc_AC['ggH'+acSample+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + + if acFlagBis: + total_NLOunc_fs_ACbis_hi += XH_ACbis_qcdunc_fs + total_NLOunc_fs_ACbis_hi += XH_ACbis_qcdunc_fs + total_NLOunc_fs_ACbis_hi += (qcdunc_ggH_powheg["ggH125_"+channel+"_"+obsName.replace('_reco','_gen')+"_genbin"+str(obsBin)]['uncerUp'] + *ggH_xsBR*acc_ACbis['ggH'+acSampleBis+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + total_NLOunc_fs_ACbis_lo += (qcdunc_ggH_powheg["ggH125_"+channel+"_"+obsName.replace('_reco','_gen')+"_genbin"+str(obsBin)]['uncerDn'] + *ggH_xsBR*acc_ACbis['ggH'+acSampleBis+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + + + print channel,total_NLOunc_fs_powheg_hi + + total_NLOunc_fs_minloHJ_hi += XH_qcdunc_fs + total_NLOunc_fs_minloHJ_lo += XH_qcdunc_fs + total_NLOunc_fs_minloHJ_hi += (qcdunc_ggH_nnlops["ggH125_NNLOPS_"+channel+"_"+obsName.replace('_reco','_gen')+"_genbin"+str(obsBin)]['uncerUp'] + *ggH_xsBR*acc_NNLOPS['ggH125_NNLOPS_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + total_NLOunc_fs_minloHJ_lo += (qcdunc_ggH_nnlops["ggH125_NNLOPS_"+channel+"_"+obsName.replace('_reco','_gen')+"_genbin"+str(obsBin)]['uncerDn'] + *ggH_xsBR*acc_NNLOPS['ggH125_NNLOPS_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + + # add pdf unc, anti correlate ggH and ttH + #NNLO + if (obsName=="mass4l"): + obsUnc_pdf_ggH_hi = unc_pdf_ggH_hi + obsUnc_pdf_ggH_lo = unc_pdf_ggH_lo + else: + obsUnc_pdf_ggH_hi = pdfunc_ggH_powheg["ggH125_"+channel+"_"+obsName.replace('_reco','_gen')+"_genbin"+str(obsBin)]['uncerUp'] + obsUnc_pdf_ggH_lo = pdfunc_ggH_powheg["ggH125_"+channel+"_"+obsName.replace('_reco','_gen')+"_genbin"+str(obsBin)]['uncerUp'] + + total_NNLOunc_fs_powheg_hi += XH_qqpdfunc_fs + total_NNLOunc_fs_powheg_lo += XH_qqpdfunc_fs + total_NNLOunc_fs_powheg_hi += (obsUnc_pdf_ggH_hi*ggH_xsBR*acc['ggH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + -unc_pdf_ttH*higgs_xs['ttH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc['ttH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + total_NNLOunc_fs_powheg_lo += (obsUnc_pdf_ggH_lo*ggH_xsBR*acc['ggH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + -unc_pdf_ttH*higgs_xs['ttH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc['ttH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + + + total_NNLOunc_fs_minloHJ_hi += XH_qqpdfunc_fs + total_NNLOunc_fs_minloHJ_lo += XH_qqpdfunc_fs + total_NNLOunc_fs_minloHJ_hi += (obsUnc_pdf_ggH_hi*ggH_xsBR*acc_NNLOPS['ggH125_NNLOPS_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + -unc_pdf_ttH*higgs_xs['ttH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc['ttH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + total_NNLOunc_fs_minloHJ_lo += (obsUnc_pdf_ggH_lo*ggH_xsBR*acc_NNLOPS['ggH125_NNLOPS_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + -unc_pdf_ttH*higgs_xs['ttH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc['ttH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + + #NLO + total_NLOunc_fs_powheg_hi += XH_qqpdfunc_fs + total_NLOunc_fs_powheg_lo += XH_qqpdfunc_fs + total_NLOunc_fs_powheg_hi += (pdfunc_ggH_powheg["ggH125_"+channel+"_"+obsName.replace('_reco','_gen')+"_genbin"+str(obsBin)]['uncerUp'] + *ggH_xsBR*acc['ggH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + -unc_pdf_ttH*higgs_xs['ttH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc['ttH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + total_NLOunc_fs_powheg_lo += (pdfunc_ggH_powheg["ggH125_"+channel+"_"+obsName.replace('_reco','_gen')+"_genbin"+str(obsBin)]['uncerDn'] + *ggH_xsBR*acc['ggH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + -unc_pdf_ttH*higgs_xs['ttH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc['ttH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + if acFlag: + total_NLOunc_fs_AC_hi += XH_AC_qqpdfunc_fs + total_NLOunc_fs_AC_lo += XH_AC_qqpdfunc_fs + total_NLOunc_fs_AC_hi += (pdfunc_ggH_powheg["ggH125_"+channel+"_"+obsName.replace('_reco','_gen')+"_genbin"+str(obsBin)]['uncerUp'] + *ggH_xsBR*acc_AC['ggH'+acSample+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + -unc_pdf_ttH*higgs_xs['ttH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc_AC['ggH'+acSample+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + total_NLOunc_fs_AC_lo += (pdfunc_ggH_powheg["ggH125_"+channel+"_"+obsName.replace('_reco','_gen')+"_genbin"+str(obsBin)]['uncerDn'] + *ggH_xsBR*acc_AC['ggH'+acSample+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + -unc_pdf_ttH*higgs_xs['ttH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc_AC['ggH'+acSample+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + if acFlagBis: + total_NLOunc_fs_ACbis_hi += XH_ACbis_qqpdfunc_fs + total_NLOunc_fs_ACbis_lo += XH_ACbis_qqpdfunc_fs + total_NLOunc_fs_ACbis_hi += (pdfunc_ggH_powheg["ggH125_"+channel+"_"+obsName.replace('_reco','_gen')+"_genbin"+str(obsBin)]['uncerUp'] + *ggH_xsBR*acc_ACbis['ggH'+acSampleBis+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + -unc_pdf_ttH*higgs_xs['ttH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc_ACbis['ggH'+acSampleBis+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + total_NLOunc_fs_ACbis_lo += (pdfunc_ggH_powheg["ggH125_"+channel+"_"+obsName.replace('_reco','_gen')+"_genbin"+str(obsBin)]['uncerDn'] + *ggH_xsBR*acc_ACbis['ggH'+acSampleBis+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + -unc_pdf_ttH*higgs_xs['ttH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc_ACbis['ggH'+acSampleBis+'_M125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + + + total_NLOunc_fs_minloHJ_hi += XH_qqpdfunc_fs + total_NLOunc_fs_minloHJ_lo += XH_qqpdfunc_fs + total_NLOunc_fs_minloHJ_hi += (pdfunc_ggH_nnlops["ggH125_NNLOPS_"+channel+"_"+obsName.replace('_reco','_gen')+"_genbin"+str(obsBin)]['uncerUp'] + *ggH_xsBR*acc_NNLOPS['ggH125_NNLOPS_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + -unc_pdf_ttH*higgs_xs['ttH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc['ttH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + total_NLOunc_fs_minloHJ_lo += (pdfunc_ggH_nnlops["ggH125_NNLOPS_"+channel+"_"+obsName.replace('_reco','_gen')+"_genbin"+str(obsBin)]['uncerDn'] + *ggH_xsBR*acc_NNLOPS['ggH125_NNLOPS_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)] + -unc_pdf_ttH*higgs_xs['ttH_'+opt.THEORYMASS]*higgs4l_br[opt.THEORYMASS+'_'+channel]*acc['ttH125_'+channel+'_'+obsName+'_genbin'+str(obsBin)+'_recobin'+str(obsBin)])**2 + + # finally total uncertainty (different final states are correlated) + # NNLO + ggH_powheg_NNLOunc_hi[obsBin]+=sqrt(total_NNLOunc_fs_powheg_hi) + ggH_powheg_NNLOunc_lo[obsBin]+=sqrt(total_NNLOunc_fs_powheg_lo) + ggH_minloHJ_NNLOunc_hi[obsBin]+=sqrt(total_NNLOunc_fs_minloHJ_hi) + ggH_minloHJ_NNLOunc_lo[obsBin]+=sqrt(total_NNLOunc_fs_minloHJ_lo) + # NLO + ggH_powheg_NLOunc_hi[obsBin]+=sqrt(total_NLOunc_fs_powheg_hi) + ggH_powheg_NLOunc_lo[obsBin]+=sqrt(total_NLOunc_fs_powheg_lo) + ggH_minloHJ_NLOunc_hi[obsBin]+=sqrt(total_NLOunc_fs_minloHJ_hi) + ggH_minloHJ_NLOunc_lo[obsBin]+=sqrt(total_NLOunc_fs_minloHJ_lo) + if(acFlag): + ggH_AC_NLOunc_hi[obsBin]+=sqrt(total_NLOunc_fs_AC_hi) + ggH_AC_NLOunc_lo[obsBin]+=sqrt(total_NLOunc_fs_AC_lo) + if(acFlagBis): + ggH_ACbis_NLOunc_hi[obsBin]+=sqrt(total_NLOunc_fs_ACbis_hi) + ggH_ACbis_NLOunc_lo[obsBin]+=sqrt(total_NLOunc_fs_ACbis_lo) + + + ggH_powheg[obsBin]+=XH[obsBin] + if(acFlag): + ggH_AC[obsBin]+=XH_AC[obsBin] + if(acFlagBis): ggH_ACbis[obsBin]+=XH_ACbis[obsBin] + ggH_minloHJ[obsBin]+=XH[obsBin] + + if chan == '4l': + if (opt.UNBLIND): + data[obsBin] = resultsXS[datamodel+"_"+obsName+"_4l_genbin"+str(obsBin)]["central"] + data_hi[obsBin] = resultsXS[datamodel+"_"+obsName+"_4l_genbin"+str(obsBin)]["uncerUp"] + data_lo[obsBin] = -1.0*resultsXS[datamodel+"_"+obsName+"_4l_genbin"+str(obsBin)]["uncerDn"] + #data_hi[obsBin] = resultsXS_LHScan["SM_125_"+obsName+"_genbin"+str(obsBin)]["uncerUp"] + #data_lo[obsBin] = -1.0*resultsXS_LHScan["SM_125_"+obsName+"_genbin"+str(obsBin)]["uncerDn"] + else: + data[obsBin] = resultsXS["SM_125_"+obsName+"_4l_genbin"+str(obsBin)]["central"] + data_hi[obsBin] = resultsXS["SM_125_"+obsName+"_4l_genbin"+str(obsBin)]["uncerUp"] + data_lo[obsBin] = -1.0*resultsXS["SM_125_"+obsName+"_4l_genbin"+str(obsBin)]["uncerDn"] + + if (opt.UNBLIND): + # modeldep_hi[obsBin] = modelIndUncert["SM_125_"+obsName+"_genbin"+str(obsBin)]["uncerUp"] + # modeldep_lo[obsBin] = -1.0*modelIndUncert["SM_125_"+obsName+"_genbin"+str(obsBin)]["uncerDn"] + systematics_hi[obsBin] = sqrt(max(0.0,resultsXS["SM_125_"+obsName+"_4l_genbin"+str(obsBin)]["uncerUp"]**2-resultsXS["SM_125_"+obsName+"_4l_genbin"+str(obsBin)+'_statOnly']["uncerUp"]**2)) + systematics_lo[obsBin] = sqrt(max(0.0,resultsXS["SM_125_"+obsName+"_4l_genbin"+str(obsBin)]["uncerDn"]**2-resultsXS["SM_125_"+obsName+"_4l_genbin"+str(obsBin)+'_statOnly']["uncerDn"]**2)) + #systematics_hi[obsBin] = sqrt(max(0.0,resultsXS_LHScan["SM_125_"+obsName+"_genbin"+str(obsBin)]["uncerUp"]**2-resultsXS_LHScan["SM_125_"+obsName+"_genbin"+str(obsBin)+'_statOnly']["uncerUp"]**2)) + #systematics_lo[obsBin] = sqrt(max(0.0,resultsXS_LHScan["SM_125_"+obsName+"_genbin"+str(obsBin)]["uncerDn"]**2-resultsXS_LHScan["SM_125_"+obsName+"_genbin"+str(obsBin)+'_statOnly']["uncerDn"]**2)) + else: + # modeldep_hi[obsBin] = modelIndUncert["AsimovData_"+obsName+"_genbin"+str(obsBin)]["uncerUp"] + # modeldep_lo[obsBin] = -1.0*modelIndUncert["AsimovData_"+obsName+"_genbin"+str(obsBin)]["uncerDn"] + systematics_hi[obsBin] = sqrt(max(0.0,resultsXS["SM_125_"+obsName+"_4l_genbin"+str(obsBin)]["uncerUp"]**2-resultsXS["SM_125_"+obsName+"_4l_genbin"+str(obsBin)+'_statOnly']["uncerUp"]**2)) + systematics_lo[obsBin] = sqrt(max(0.0,resultsXS["SM_125_"+obsName+"_4l_genbin"+str(obsBin)]["uncerDn"]**2-resultsXS["SM_125_"+obsName+"_4l_genbin"+str(obsBin)+'_statOnly']["uncerDn"]**2)) + stat_hi[obsBin] = resultsXS["SM_125_"+obsName+"_4l_genbin"+str(obsBin)+'_statOnly']["uncerUp"] + stat_lo[obsBin] = resultsXS["SM_125_"+obsName+"_4l_genbin"+str(obsBin)+'_statOnly']["uncerDn"] + else: + if (opt.UNBLIND): + data[obsBin] = resultsXS[datamodel+"_"+obsName+"_2e2mu_genbin"+str(obsBin)]["central"] + data_hi[obsBin] = resultsXS[datamodel+"_"+obsName+"_2e2mu_genbin"+str(obsBin)]["uncerUp"] + data_lo[obsBin] = -1.0*resultsXS[datamodel+"_"+obsName+"_2e2mu_genbin"+str(obsBin)]["uncerDn"] + #data_hi[obsBin] = resultsXS_LHScan["SM_125_"+obsName+"_genbin"+str(obsBin)]["uncerUp"] + #data_lo[obsBin] = -1.0*resultsXS_LHScan["SM_125_"+obsName+"_genbin"+str(obsBin)]["uncerDn"] + else: + data[obsBin] = resultsXS["SM_125_"+obsName+"_2e2mu_genbin"+str(obsBin)]["central"] + data_hi[obsBin] = resultsXS["SM_125_"+obsName+"_2e2mu_genbin"+str(obsBin)]["uncerUp"] + data_lo[obsBin] = -1.0*resultsXS["SM_125_"+obsName+"_2e2mu_genbin"+str(obsBin)]["uncerDn"] + + if (opt.UNBLIND): + # modeldep_hi[obsBin] = modelIndUncert["SM_125_"+obsName+"_genbin"+str(obsBin)]["uncerUp"] + # modeldep_lo[obsBin] = -1.0*modelIndUncert["SM_125_"+obsName+"_genbin"+str(obsBin)]["uncerDn"] + systematics_hi[obsBin] = sqrt(max(0.0,resultsXS["SM_125_"+obsName+"_2e2mu_genbin"+str(obsBin)]["uncerUp"]**2-resultsXS["SM_125_"+obsName+"_2e2mu_genbin"+str(obsBin)+'_statOnly']["uncerUp"]**2)) + systematics_lo[obsBin] = sqrt(max(0.0,resultsXS["SM_125_"+obsName+"_2e2mu_genbin"+str(obsBin)]["uncerDn"]**2-resultsXS["SM_125_"+obsName+"_2e2mu_genbin"+str(obsBin)+'_statOnly']["uncerDn"]**2)) + #systematics_hi[obsBin] = sqrt(max(0.0,resultsXS_LHScan["SM_125_"+obsName+"_genbin"+str(obsBin)]["uncerUp"]**2-resultsXS_LHScan["SM_125_"+obsName+"_genbin"+str(obsBin)+'_statOnly']["uncerUp"]**2)) + #systematics_lo[obsBin] = sqrt(max(0.0,resultsXS_LHScan["SM_125_"+obsName+"_genbin"+str(obsBin)]["uncerDn"]**2-resultsXS_LHScan["SM_125_"+obsName+"_genbin"+str(obsBin)+'_statOnly']["uncerDn"]**2)) + else: + # modeldep_hi[obsBin] = modelIndUncert["AsimovData_"+obsName+"_genbin"+str(obsBin)]["uncerUp"] + # modeldep_lo[obsBin] = -1.0*modelIndUncert["AsimovData_"+obsName+"_genbin"+str(obsBin)]["uncerDn"] + systematics_hi[obsBin] = sqrt(max(0.0,resultsXS["SM_125_"+obsName+"_2e2mu_genbin"+str(obsBin)]["uncerUp"]**2-resultsXS["SM_125_"+obsName+"_2e2mu_genbin"+str(obsBin)+'_statOnly']["uncerUp"]**2)) + systematics_lo[obsBin] = sqrt(max(0.0,resultsXS["SM_125_"+obsName+"_2e2mu_genbin"+str(obsBin)]["uncerDn"]**2-resultsXS["SM_125_"+obsName+"_2e2mu_genbin"+str(obsBin)+'_statOnly']["uncerDn"]**2)) + stat_hi[obsBin] = resultsXS["SM_125_"+obsName+"_2e2mu_genbin"+str(obsBin)+'_statOnly']["uncerUp"] + stat_lo[obsBin] = resultsXS["SM_125_"+obsName+"_2e2mu_genbin"+str(obsBin)+'_statOnly']["uncerDn"] + data_hi_allunc[obsBin] = sqrt(data_hi[obsBin]**2+modeldep_hi[obsBin]**2) + data_lo_allunc[obsBin] = sqrt(data_lo[obsBin]**2+modeldep_lo[obsBin]**2) + + obsBin +=1 + + print 'data',data + sumdata = 0.0 + for i in range(len(data)): + sumdata+=data[i] + print obsName,'sum data',sumdata + print 'data_hi',data_hi + print 'data_lo',data_lo + #print 'ggH HRes + XH',ggH_HRes + #print 'NNLO ggH HRes + XH',ggH_HRes_NNLOunc_hi + #print 'NNLO ggH HRes + XH',ggH_HRes_NNLOunc_lo + print 'ggH_powheg',ggH_powheg + if acFlag: + print 'ggH_AC',ggH_AC + if acFlagBis: + print 'ggH_ACbis',ggH_ACbis + print 'NLO ggH_powheg_hi',ggH_powheg_NLOunc_hi + print 'NLO ggH_powheg_lo',ggH_powheg_NLOunc_lo + print 'NNLO ggH_powheg_hi',ggH_powheg_NNLOunc_hi + print 'NNLO ggH_powheg_lo',ggH_powheg_NNLOunc_lo + print 'OLD ggH_powheg_hi',ggH_powheg_unc_hi + print 'OLD ggH_powheg_lo',ggH_powheg_unc_lo + print 'ggH_minloHJ',ggH_minloHJ + print 'ggH_minloHJ_NNLOunc_hi',ggH_minloHJ_NNLOunc_hi + print 'ggH_minloHJ_NNLOunc_lo',ggH_minloHJ_NNLOunc_lo + print 'XH',XH + print 'XH_unc',XH_unc + if acFlag: + print 'XH_AC',XH_AC + print 'XH_AC_unc',XH_AC_unc + print 'ggH_AC_NLOunc_hi', ggH_AC_NLOunc_hi + print 'ggH_AC_NLOunc_lo', ggH_AC_NLOunc_lo + if acFlagBis: + print 'XH_ACbis',XH_ACbis + print 'XH_ACbis_unc',XH_ACbis_unc + print 'ggH_ACbis_NLOunc_hi', ggH_ACbis_NLOunc_hi + print 'ggH_ACbis_NLOunc_lo', ggH_ACbis_NLOunc_lo + print 'modedlep_hi',modeldep_hi + print 'modeldep_lo',modeldep_lo + print 'systematics_hi',systematics_hi + print 'systematics_lo',systematics_lo + print 'stat_hi',stat_hi + print 'stat_lo',stat_lo + + if doubleDiff: + offset = 20.0 + a_observable = array('d',[0.5*(float(obs_bins[i])+float(obs_bins[i+1])) for i in range(len(obs_bins)-1)]) + v_observable = TVectorD(len(a_observable),a_observable) + a_dobservable = array('d',[0.5*(float(obs_bins[i+1])-float(obs_bins[i])) for i in range(len(obs_bins)-1)]) + v_dobservable = TVectorD(len(a_dobservable),a_dobservable) + + a_observable_1 = array('d',[(0.5*(float(obs_bins[i])+float(obs_bins[i+1]))+min(offset,0.25*(float(obs_bins[i+1])-float(obs_bins[i])))) for i in range(len(obs_bins)-1)]) + v_observable_1 = TVectorD(len(a_observable_1),a_observable_1) + a_dobservable_1 = array('d',[0.125*(float(obs_bins[i+1])-float(obs_bins[i])) for i in range(len(obs_bins)-1)]) + v_dobservable_1 = TVectorD(len(a_dobservable_1),a_dobservable_1) + + a_observable_2 = array('d',[(0.5*(float(obs_bins[i])+float(obs_bins[i+1]))-min(offset,0.25*(float(obs_bins[i+1])-float(obs_bins[i])))) for i in range(len(obs_bins)-1)]) + v_observable_2 = TVectorD(len(a_observable_2),a_observable_2) + a_dobservable_2 = array('d',[0.125*(float(obs_bins[i+1])-float(obs_bins[i])) for i in range(len(obs_bins)-1)]) + v_dobservable_2 = TVectorD(len(a_dobservable_2),a_dobservable_2) + + a_zeros = array('d',[0.0 for i in range(len(obs_bins)-1)]) + v_zeros = TVectorD(len(a_zeros),a_zeros) + a_twos = array('d',[0.015*(float(obs_bins[len(obs_bins)-1])-float(obs_bins[0])) for i in range(len(obs_bins)-1)]) + v_twos = TVectorD(len(a_twos),a_twos) + + a_ggH_powheg = array('d',[ggH_powheg[i]/((float(obs_bins_boundaries[i][1])-float(obs_bins_boundaries[i][0]))*(float(obs_bins_boundaries[i][3])-float(obs_bins_boundaries[i][2]))) for i in range(len(ggH_powheg))]) + v_ggH_powheg = TVectorD(len(a_ggH_powheg),a_ggH_powheg) + a_ggH_powheg_unc_hi = array('d',[ggH_powheg_NLOunc_hi[i]/((float(obs_bins_boundaries[i][1])-float(obs_bins_boundaries[i][0]))*(float(obs_bins_boundaries[i][3])-float(obs_bins_boundaries[i][2]))) for i in range(len(ggH_powheg_unc_hi))]) + a_ggH_powheg_unc_lo = array('d',[ggH_powheg_NLOunc_lo[i]/((float(obs_bins_boundaries[i][1])-float(obs_bins_boundaries[i][0]))*(float(obs_bins_boundaries[i][3])-float(obs_bins_boundaries[i][2]))) for i in range(len(ggH_powheg_unc_lo))]) + v_ggH_powheg_unc_hi = TVectorD(len(a_ggH_powheg_unc_hi),a_ggH_powheg_unc_hi) + v_ggH_powheg_unc_lo = TVectorD(len(a_ggH_powheg_unc_lo),a_ggH_powheg_unc_lo) + + a_ggH_minloHJ = array('d',[ggH_minloHJ[i]/((float(obs_bins_boundaries[i][1])-float(obs_bins_boundaries[i][0]))*(float(obs_bins_boundaries[i][3])-float(obs_bins_boundaries[i][2]))) for i in range(len(ggH_minloHJ))]) + v_ggH_minloHJ = TVectorD(len(a_ggH_minloHJ),a_ggH_minloHJ) + a_ggH_minloHJ_unc_hi = array('d',[ggH_minloHJ_NNLOunc_hi[i]/((float(obs_bins_boundaries[i][1])-float(obs_bins_boundaries[i][0]))*(float(obs_bins_boundaries[i][3])-float(obs_bins_boundaries[i][2]))) for i in range(len(ggH_minloHJ_unc_hi))]) + a_ggH_minloHJ_unc_lo = array('d',[ggH_minloHJ_NNLOunc_lo[i]/((float(obs_bins_boundaries[i][1])-float(obs_bins_boundaries[i][0]))*(float(obs_bins_boundaries[i][3])-float(obs_bins_boundaries[i][2]))) for i in range(len(ggH_minloHJ_unc_lo))]) + v_ggH_minloHJ_unc_hi = TVectorD(len(a_ggH_minloHJ_unc_hi),a_ggH_minloHJ_unc_hi) + v_ggH_minloHJ_unc_lo = TVectorD(len(a_ggH_minloHJ_unc_lo),a_ggH_minloHJ_unc_lo) + + ''' + a_ggH_HRes = array('d',[ggH_HRes[i]/((float(obs_bins_boundaries[i][1])-float(obs_bins_boundaries[i][0]))*(float(obs_bins_boundaries[i][3])-float(obs_bins_boundaries[i][2]))) for i in range(len(ggH_HRes))]) + v_ggH_HRes = TVectorD(len(a_ggH_HRes),a_ggH_HRes) + a_ggH_HRes_unc_hi = array('d',[ggH_HRes_NNLOunc_hi[i]/((float(obs_bins_boundaries[i][1])-float(obs_bins_boundaries[i][0]))*(float(obs_bins_boundaries[i][3])-float(obs_bins_boundaries[i][2]))) for i in range(len(ggH_HRes_unc_hi))]) + a_ggH_HRes_unc_lo = array('d',[ggH_HRes_NNLOunc_lo[i]/((float(obs_bins_boundaries[i][1])-float(obs_bins_boundaries[i][0]))*(float(obs_bins_boundaries[i][3])-float(obs_bins_boundaries[i][2]))) for i in range(len(ggH_HRes_unc_lo))]) + v_ggH_HRes_unc_hi = TVectorD(len(a_ggH_HRes_unc_hi),a_ggH_HRes_unc_hi) + v_ggH_HRes_unc_lo = TVectorD(len(a_ggH_HRes_unc_lo),a_ggH_HRes_unc_lo) + ''' + + a_XH = array('d',[XH[i]/((float(obs_bins_boundaries[i][1])-float(obs_bins_boundaries[i][0]))*(float(obs_bins_boundaries[i][3])-float(obs_bins_boundaries[i][2]))) for i in range(len(XH))]) + v_XH = TVectorD(len(a_XH),a_XH) + + a_XH_hi = array('d',[XH_unc[i]/((float(obs_bins_boundaries[i][1])-float(obs_bins_boundaries[i][0]))*(float(obs_bins_boundaries[i][3])-float(obs_bins_boundaries[i][2]))) for i in range(len(XH_unc))]) + a_XH_lo = array('d',[XH_unc[i]/((float(obs_bins_boundaries[i][1])-float(obs_bins_boundaries[i][0]))*(float(obs_bins_boundaries[i][3])-float(obs_bins_boundaries[i][2]))) for i in range(len(XH_unc))]) + v_XH_hi = TVectorD(len(a_XH_hi),a_XH_hi) + v_XH_lo = TVectorD(len(a_XH_lo),a_XH_lo) + + a_data = array('d',[data[i]/((float(obs_bins_boundaries[i][1])-float(obs_bins_boundaries[i][0]))*(float(obs_bins_boundaries[i][3])-float(obs_bins_boundaries[i][2]))) for i in range(len(data))]) + v_data = TVectorD(len(a_data),a_data) + a_data_hi = array('d',[data_hi[i]/((float(obs_bins_boundaries[i][1])-float(obs_bins_boundaries[i][0]))*(float(obs_bins_boundaries[i][3])-float(obs_bins_boundaries[i][2]))) for i in range(len(data_hi))]) + v_data_hi = TVectorD(len(a_data_hi),a_data_hi) + a_data_lo = array('d',[data_lo[i]/((float(obs_bins_boundaries[i][1])-float(obs_bins_boundaries[i][0]))*(float(obs_bins_boundaries[i][3])-float(obs_bins_boundaries[i][2]))) for i in range(len(data_lo))]) + v_data_lo = TVectorD(len(a_data_lo),a_data_lo) + + a_data_hi2 = array('d',[data_hi2[i]/((float(obs_bins_boundaries[i][1])-float(obs_bins_boundaries[i][0]))*(float(obs_bins_boundaries[i][3])-float(obs_bins_boundaries[i][2]))) for i in range(len(data_hi2))]) + v_data_hi2 = TVectorD(len(a_data_hi2),a_data_hi2) + a_data_lo2 = array('d',[data_lo2[i]/((float(obs_bins_boundaries[i][1])-float(obs_bins_boundaries[i][0]))*(float(obs_bins_boundaries[i][3])-float(obs_bins_boundaries[i][2]))) for i in range(len(data_lo2))]) + v_data_lo2 = TVectorD(len(a_data_lo2),a_data_lo2) + a_systematics_hi = array('d',[(systematics_hi[i])/((float(obs_bins_boundaries[i][1])-float(obs_bins_boundaries[i][0]))*(float(obs_bins_boundaries[i][3])-float(obs_bins_boundaries[i][2]))) for i in range(len(systematics_hi))]) + v_systematics_hi = TVectorD(len(a_systematics_hi),a_systematics_hi) + a_systematics_lo = array('d',[(systematics_lo[i])/((float(obs_bins_boundaries[i][1])-float(obs_bins_boundaries[i][0]))*(float(obs_bins_boundaries[i][3])-float(obs_bins_boundaries[i][2]))) for i in range(len(systematics_lo))]) + v_systematics_lo = TVectorD(len(a_systematics_lo),a_systematics_lo) + + a_systematics_hi2 = array('d',[(systematics_hi2[i])/((float(obs_bins_boundaries[i][1])-float(obs_bins_boundaries[i][0]))*(float(obs_bins_boundaries[i][3])-float(obs_bins_boundaries[i][2]))) for i in range(len(systematics_hi2))]) + v_systematics_hi2 = TVectorD(len(a_systematics_hi2),a_systematics_hi2) + a_systematics_lo2 = array('d',[(systematics_lo2[i])/((float(obs_bins_boundaries[i][1])-float(obs_bins_boundaries[i][0]))*(float(obs_bins_boundaries[i][3])-float(obs_bins_boundaries[i][2]))) for i in range(len(systematics_lo2))]) + v_systematics_lo2 = TVectorD(len(a_systematics_lo2),a_systematics_lo2) + + a_modeldep_hi = array('d',[(modeldep_hi[i])/((float(obs_bins_boundaries[i][1])-float(obs_bins_boundaries[i][0]))*(float(obs_bins_boundaries[i][3])-float(obs_bins_boundaries[i][2]))) for i in range(len(modeldep_hi))]) + v_modeldep_hi = TVectorD(len(a_modeldep_hi),a_modeldep_hi) + a_modeldep_lo = array('d',[(modeldep_lo[i])/((float(obs_bins_boundaries[i][1])-float(obs_bins_boundaries[i][0]))*(float(obs_bins_boundaries[i][3])-float(obs_bins_boundaries[i][2]))) for i in range(len(modeldep_lo))]) + v_modeldep_lo = TVectorD(len(a_modeldep_lo),a_modeldep_lo) + + v_data_hi_allunc = TVectorD(len(data_hi_allunc), array('d',[data_hi_allunc[i] for i in range(len(data_hi_allunc))])) + v_data_lo_allunc = TVectorD(len(data_lo_allunc), array('d',[data_lo_allunc[i] for i in range(len(data_lo_allunc))])) + + else: + if (obsName=="pT4l"): offset=20.0 + elif (obsName=="massZ2"): offset=20.0 + elif (obsName=="massZ1"): offset=20.0 + elif (obsName=="rapidity4l"): offset=20.0 + elif (obsName=="pTj1jet_pt30_eta2p5"): offset=30.0 + elif (obsName=="pTj1"): offset=30.0 + elif (obsName=="njets_pt30_eta2p5"): offset=999.0 + else: offset = 20.0 + + a_observable = array('d',[0.5*(float(obs_bins[i])+float(obs_bins[i+1])) for i in range(len(obs_bins)-1)]) + v_observable = TVectorD(len(a_observable),a_observable) + a_dobservable = array('d',[0.5*(float(obs_bins[i+1])-float(obs_bins[i])) for i in range(len(obs_bins)-1)]) + v_dobservable = TVectorD(len(a_dobservable),a_dobservable) + + a_observable_1 = array('d',[(0.5*(float(obs_bins[i])+float(obs_bins[i+1]))+min(offset,0.25*(float(obs_bins[i+1])-float(obs_bins[i])))) for i in range(len(obs_bins)-1)]) + v_observable_1 = TVectorD(len(a_observable_1),a_observable_1) + a_dobservable_1 = array('d',[0.125*(float(obs_bins[i+1])-float(obs_bins[i])) for i in range(len(obs_bins)-1)]) + v_dobservable_1 = TVectorD(len(a_dobservable_1),a_dobservable_1) + + a_observable_2 = array('d',[(0.5*(float(obs_bins[i])+float(obs_bins[i+1]))-min(offset,0.25*(float(obs_bins[i+1])-float(obs_bins[i])))) for i in range(len(obs_bins)-1)]) + v_observable_2 = TVectorD(len(a_observable_2),a_observable_2) + a_dobservable_2 = array('d',[0.125*(float(obs_bins[i+1])-float(obs_bins[i])) for i in range(len(obs_bins)-1)]) + v_dobservable_2 = TVectorD(len(a_dobservable_2),a_dobservable_2) + + a_zeros = array('d',[0.0 for i in range(len(obs_bins)-1)]) + v_zeros = TVectorD(len(a_zeros),a_zeros) + a_twos = array('d',[0.015*(float(obs_bins[len(obs_bins)-1])-float(obs_bins[0])) for i in range(len(obs_bins)-1)]) + v_twos = TVectorD(len(a_twos),a_twos) + + a_ggH_powheg = array('d',[ggH_powheg[i]/(float(obs_bins[i+1])-float(obs_bins[i])) for i in range(len(ggH_powheg))]) + v_ggH_powheg = TVectorD(len(a_ggH_powheg),a_ggH_powheg) + a_ggH_powheg_unc_hi = array('d',[ggH_powheg_NLOunc_hi[i]/(float(obs_bins[i+1])-float(obs_bins[i])) for i in range(len(ggH_powheg_unc_hi))]) + a_ggH_powheg_unc_lo = array('d',[ggH_powheg_NLOunc_lo[i]/(float(obs_bins[i+1])-float(obs_bins[i])) for i in range(len(ggH_powheg_unc_lo))]) + v_ggH_powheg_unc_hi = TVectorD(len(a_ggH_powheg_unc_hi),a_ggH_powheg_unc_hi) + v_ggH_powheg_unc_lo = TVectorD(len(a_ggH_powheg_unc_lo),a_ggH_powheg_unc_lo) + + if acFlag: + a_ggH_AC = array('d',[ggH_AC[i]/(float(obs_bins[i+1])-float(obs_bins[i])) for i in range(len(ggH_AC))]) + v_ggH_AC = TVectorD(len(a_ggH_AC),a_ggH_AC) + a_ggH_AC_unc_hi = array('d',[ggH_AC_NLOunc_hi[i]/(float(obs_bins[i+1])-float(obs_bins[i])) for i in range(len(ggH_AC_unc_hi))]) + a_ggH_AC_unc_lo = array('d',[ggH_AC_NLOunc_lo[i]/(float(obs_bins[i+1])-float(obs_bins[i])) for i in range(len(ggH_AC_unc_lo))]) + v_ggH_AC_unc_hi = TVectorD(len(a_ggH_AC_unc_hi),a_ggH_AC_unc_hi) + v_ggH_AC_unc_lo = TVectorD(len(a_ggH_AC_unc_lo),a_ggH_AC_unc_lo) + if acFlagBis: + a_ggH_ACbis = array('d',[ggH_ACbis[i]/(float(obs_bins[i+1])-float(obs_bins[i])) for i in range(len(ggH_ACbis))]) + v_ggH_ACbis = TVectorD(len(a_ggH_ACbis),a_ggH_ACbis) + a_ggH_ACbis_unc_hi = array('d',[ggH_ACbis_NLOunc_hi[i]/(float(obs_bins[i+1])-float(obs_bins[i])) for i in range(len(ggH_ACbis_unc_hi))]) + a_ggH_ACbis_unc_lo = array('d',[ggH_ACbis_NLOunc_lo[i]/(float(obs_bins[i+1])-float(obs_bins[i])) for i in range(len(ggH_ACbis_unc_lo))]) + v_ggH_ACbis_unc_hi = TVectorD(len(a_ggH_ACbis_unc_hi),a_ggH_ACbis_unc_hi) + v_ggH_ACbis_unc_lo = TVectorD(len(a_ggH_ACbis_unc_lo),a_ggH_ACbis_unc_lo) + + a_ggH_minloHJ = array('d',[ggH_minloHJ[i]/(float(obs_bins[i+1])-float(obs_bins[i])) for i in range(len(ggH_minloHJ))]) + v_ggH_minloHJ = TVectorD(len(a_ggH_minloHJ),a_ggH_minloHJ) + a_ggH_minloHJ_unc_hi = array('d',[ggH_minloHJ_NNLOunc_hi[i]/(float(obs_bins[i+1])-float(obs_bins[i])) for i in range(len(ggH_minloHJ_unc_hi))]) + a_ggH_minloHJ_unc_lo = array('d',[ggH_minloHJ_NNLOunc_lo[i]/(float(obs_bins[i+1])-float(obs_bins[i])) for i in range(len(ggH_minloHJ_unc_lo))]) + v_ggH_minloHJ_unc_hi = TVectorD(len(a_ggH_minloHJ_unc_hi),a_ggH_minloHJ_unc_hi) + v_ggH_minloHJ_unc_lo = TVectorD(len(a_ggH_minloHJ_unc_lo),a_ggH_minloHJ_unc_lo) + + ''' + a_ggH_HRes = array('d',[ggH_HRes[i]/(float(obs_bins[i+1])-float(obs_bins[i])) for i in range(len(ggH_HRes))]) + v_ggH_HRes = TVectorD(len(a_ggH_HRes),a_ggH_HRes) + a_ggH_HRes_unc_hi = array('d',[ggH_HRes_NNLOunc_hi[i]/(float(obs_bins[i+1])-float(obs_bins[i])) for i in range(len(ggH_HRes_unc_hi))]) + a_ggH_HRes_unc_lo = array('d',[ggH_HRes_NNLOunc_lo[i]/(float(obs_bins[i+1])-float(obs_bins[i])) for i in range(len(ggH_HRes_unc_lo))]) + v_ggH_HRes_unc_hi = TVectorD(len(a_ggH_HRes_unc_hi),a_ggH_HRes_unc_hi) + v_ggH_HRes_unc_lo = TVectorD(len(a_ggH_HRes_unc_lo),a_ggH_HRes_unc_lo) + ''' + + a_XH = array('d',[XH[i]/(float(obs_bins[i+1])-float(obs_bins[i])) for i in range(len(XH))]) + v_XH = TVectorD(len(a_XH),a_XH) + + a_XH_hi = array('d',[XH_unc[i]/(float(obs_bins[i+1])-float(obs_bins[i])) for i in range(len(XH_unc))]) + a_XH_lo = array('d',[XH_unc[i]/(float(obs_bins[i+1])-float(obs_bins[i])) for i in range(len(XH_unc))]) + v_XH_hi = TVectorD(len(a_XH_hi),a_XH_hi) + v_XH_lo = TVectorD(len(a_XH_lo),a_XH_lo) + + a_data = array('d',[data[i]/(float(obs_bins[i+1])-float(obs_bins[i])) for i in range(len(data))]) + v_data = TVectorD(len(a_data),a_data) + a_data_hi = array('d',[data_hi[i]/(float(obs_bins[i+1])-float(obs_bins[i])) for i in range(len(data_hi))]) + v_data_hi = TVectorD(len(a_data_hi),a_data_hi) + a_data_lo = array('d',[data_lo[i]/(float(obs_bins[i+1])-float(obs_bins[i])) for i in range(len(data_lo))]) + v_data_lo = TVectorD(len(a_data_lo),a_data_lo) + + a_data_hi2 = array('d',[data_hi2[i]/(float(obs_bins[i+1])-float(obs_bins[i])) for i in range(len(data_hi2))]) + v_data_hi2 = TVectorD(len(a_data_hi2),a_data_hi2) + a_data_lo2 = array('d',[data_lo2[i]/(float(obs_bins[i+1])-float(obs_bins[i])) for i in range(len(data_lo2))]) + v_data_lo2 = TVectorD(len(a_data_lo2),a_data_lo2) + a_systematics_hi = array('d',[(systematics_hi[i])/(float(obs_bins[i+1])-float(obs_bins[i])) for i in range(len(systematics_hi))]) + v_systematics_hi = TVectorD(len(a_systematics_hi),a_systematics_hi) + a_systematics_lo = array('d',[(systematics_lo[i])/(float(obs_bins[i+1])-float(obs_bins[i])) for i in range(len(systematics_lo))]) + v_systematics_lo = TVectorD(len(a_systematics_lo),a_systematics_lo) + + a_systematics_hi2 = array('d',[(systematics_hi2[i])/(float(obs_bins[i+1])-float(obs_bins[i])) for i in range(len(systematics_hi2))]) + v_systematics_hi2 = TVectorD(len(a_systematics_hi2),a_systematics_hi2) + a_systematics_lo2 = array('d',[(systematics_lo2[i])/(float(obs_bins[i+1])-float(obs_bins[i])) for i in range(len(systematics_lo2))]) + v_systematics_lo2 = TVectorD(len(a_systematics_lo2),a_systematics_lo2) + + a_modeldep_hi = array('d',[(modeldep_hi[i])/(float(obs_bins[i+1])-float(obs_bins[i])) for i in range(len(modeldep_hi))]) + v_modeldep_hi = TVectorD(len(a_modeldep_hi),a_modeldep_hi) + a_modeldep_lo = array('d',[(modeldep_lo[i])/(float(obs_bins[i+1])-float(obs_bins[i])) for i in range(len(modeldep_lo))]) + v_modeldep_lo = TVectorD(len(a_modeldep_lo),a_modeldep_lo) + + v_data_hi_allunc = TVectorD(len(data_hi_allunc), array('d',[data_hi_allunc[i] for i in range(len(data_hi_allunc))])) + v_data_lo_allunc = TVectorD(len(data_lo_allunc), array('d',[data_lo_allunc[i] for i in range(len(data_lo_allunc))])) + + + g_ggH_powheg = TGraphAsymmErrors(v_observable_1,v_ggH_powheg,v_dobservable_1,v_dobservable_1,v_ggH_powheg_unc_lo,v_ggH_powheg_unc_hi) + g_ggH_powheg.SetFillStyle(3254); + g_ggH_powheg.SetFillColor(ROOT.kAzure+2) + g_ggH_powheg.SetLineColor(ROOT.kAzure+2) + g_ggH_powheg.SetLineWidth(2) + g_ggH_powheg.SetMarkerColor(ROOT.kAzure+2) + + g_ggH_powhegBorder = TGraphAsymmErrors(v_observable_1,v_ggH_powheg,v_dobservable_1,v_dobservable_1,v_ggH_powheg_unc_lo,v_ggH_powheg_unc_hi) + g_ggH_powhegBorder.SetFillStyle(0) + g_ggH_powhegBorder.SetFillColor(ROOT.kAzure+2) + g_ggH_powhegBorder.SetLineColor(ROOT.kAzure+2) + g_ggH_powhegBorder.SetMarkerColor(ROOT.kAzure+2) + + g_ggH_powhege0 = TGraphAsymmErrors(v_observable,v_ggH_powheg,v_dobservable,v_dobservable,v_zeros,v_zeros) + g_ggH_powhege0.SetFillStyle(3254); + g_ggH_powhege0.SetFillColor(ROOT.kAzure+2) + g_ggH_powhege0.SetLineColor(ROOT.kAzure+2) + g_ggH_powhege0.SetMarkerColor(ROOT.kAzure+2) + + if (obsName=="mass4l"): + + g_ggH_powheg = TGraphAsymmErrors(v_observable_1,v_ggH_powheg,v_dobservable_1,v_dobservable_1,v_ggH_powheg_unc_lo,v_ggH_powheg_unc_hi) + g_ggH_powheg.SetFillStyle(3254); + g_ggH_powheg.SetFillColor(ROOT.kAzure+2) + g_ggH_powheg.SetLineColor(ROOT.kAzure+2) + g_ggH_powheg.SetLineWidth(2) + g_ggH_powheg.SetMarkerColor(ROOT.kAzure+2) + + g_ggH_powhegBorder = TGraphAsymmErrors(v_observable_1,v_ggH_powheg,v_dobservable_1,v_dobservable_1,v_ggH_powheg_unc_lo,v_ggH_powheg_unc_hi) + g_ggH_powhegBorder.SetFillStyle(0) + g_ggH_powhegBorder.SetFillColor(ROOT.kAzure+2) + g_ggH_powhegBorder.SetLineColor(ROOT.kAzure+2) + g_ggH_powhegBorder.SetMarkerColor(ROOT.kAzure+2) + + h_ggH_powheg = TH1D("h_ggH_powheg","h_ggH_powheg",4, 0, 4) + for i in range(4): + h_ggH_powheg.SetBinContent(i+1,v_ggH_powheg[i]) + elif doubleDiff: + g_ggH_powheg = TGraphAsymmErrors(v_observable_1,v_ggH_powheg,v_dobservable_1,v_dobservable_1,v_ggH_powheg_unc_lo,v_ggH_powheg_unc_hi) + g_ggH_powheg.SetFillStyle(3254); + g_ggH_powheg.SetFillColor(ROOT.kAzure+2) + g_ggH_powheg.SetLineColor(ROOT.kAzure+2) + g_ggH_powheg.SetLineWidth(2) + g_ggH_powheg.SetMarkerColor(ROOT.kAzure+2) + + g_ggH_powhegBorder = TGraphAsymmErrors(v_observable_1,v_ggH_powheg,v_dobservable_1,v_dobservable_1,v_ggH_powheg_unc_lo,v_ggH_powheg_unc_hi) + g_ggH_powhegBorder.SetFillStyle(0) + g_ggH_powhegBorder.SetFillColor(ROOT.kAzure+2) + g_ggH_powhegBorder.SetLineColor(ROOT.kAzure+2) + g_ggH_powhegBorder.SetMarkerColor(ROOT.kAzure+2) + + h_ggH_powheg = TH1D("h_ggH_powheg","h_ggH_powheg",5, 0, 5) + for i in range(5): + h_ggH_powheg.SetBinContent(i+1,v_ggH_powheg[i]) + else: + g_ggH_powheg = TGraphAsymmErrors(v_observable_1,v_ggH_powheg,v_dobservable_1,v_dobservable_1,v_ggH_powheg_unc_lo,v_ggH_powheg_unc_hi) + g_ggH_powheg.SetFillStyle(3254); + g_ggH_powheg.SetFillColor(ROOT.kAzure+2) + g_ggH_powheg.SetLineColor(ROOT.kAzure+2) + g_ggH_powheg.SetLineWidth(2) + g_ggH_powheg.SetMarkerColor(ROOT.kAzure+2) + + g_ggH_powhegBorder = TGraphAsymmErrors(v_observable_1,v_ggH_powheg,v_dobservable_1,v_dobservable_1,v_ggH_powheg_unc_lo,v_ggH_powheg_unc_hi) + g_ggH_powhegBorder.SetFillStyle(0) + g_ggH_powhegBorder.SetFillColor(ROOT.kAzure+2) + g_ggH_powhegBorder.SetLineColor(ROOT.kAzure+2) + g_ggH_powhegBorder.SetMarkerColor(ROOT.kAzure+2) + + if acFlag: + g_ggH_AC = TGraphAsymmErrors(v_observable_2,v_ggH_AC,v_dobservable_2,v_dobservable_2,v_ggH_AC_unc_lo,v_ggH_AC_unc_hi) + g_ggH_AC.SetFillStyle(3254); + g_ggH_AC.SetFillColor(ROOT.kRed+2) + g_ggH_AC.SetLineColor(ROOT.kRed+2) + g_ggH_AC.SetLineWidth(2) + g_ggH_AC.SetMarkerColor(ROOT.kRed+2) + + g_ggH_ACBorder = TGraphAsymmErrors(v_observable_2,v_ggH_AC,v_dobservable_2,v_dobservable_2,v_ggH_AC_unc_lo,v_ggH_AC_unc_hi) + g_ggH_ACBorder.SetFillStyle(0) + g_ggH_ACBorder.SetFillColor(ROOT.kRed+2) + g_ggH_ACBorder.SetLineColor(ROOT.kRed+2) + g_ggH_ACBorder.SetMarkerColor(ROOT.kRed+2) + + if acFlagBis: + g_ggH_ACbis = TGraphAsymmErrors(v_observable_2,v_ggH_ACbis,v_dobservable_2,v_dobservable_2,v_ggH_ACbis_unc_lo,v_ggH_ACbis_unc_hi) + g_ggH_ACbis.SetFillStyle(3254); + g_ggH_ACbis.SetFillColor(ROOT.kViolet+2) + g_ggH_ACbis.SetLineColor(ROOT.kViolet+2) + g_ggH_ACbis.SetLineWidth(2) + g_ggH_ACbis.SetMarkerColor(ROOT.kViolet+2) + + g_ggH_ACbisBorder = TGraphAsymmErrors(v_observable_2,v_ggH_ACbis,v_dobservable_2,v_dobservable_2,v_ggH_ACbis_unc_lo,v_ggH_ACbis_unc_hi) + g_ggH_ACbisBorder.SetFillStyle(0) + g_ggH_ACbisBorder.SetFillColor(ROOT.kViolet+2) + g_ggH_ACbisBorder.SetLineColor(ROOT.kViolet+2) + g_ggH_ACbisBorder.SetMarkerColor(ROOT.kViolet+2) + + + if ("jet" in obsName and (not obsName.startswith("njets"))) : + h_ggH_powheg = TH1D("h_ggH_powheg","h_ggH_powheg",nBins-2, array('d',[float(obs_bins[i]) for i in range(1,len(obs_bins))]) ) + for i in range(1,nBins-1): + h_ggH_powheg.SetBinContent(i,v_ggH_powheg[i]) + else: + h_ggH_powheg = TH1D("h_ggH_powheg","h_ggH_powheg",nBins-1, array('d',[float(obs_bins[i]) for i in range(len(obs_bins))]) ) + for i in range(nBins-1): + h_ggH_powheg.SetBinContent(i+1,v_ggH_powheg[i]) + if acFlag: + h_ggH_AC = TH1D("h_ggH_AC","h_ggH_AC",nBins-1, array('d',[float(obs_bins[i]) for i in range(len(obs_bins))]) ) + for i in range(nBins-1): + h_ggH_AC.SetBinContent(i+1,v_ggH_AC[i]) + + if acFlagBis: + h_ggH_ACbis = TH1D("h_ggH_ACbis","h_ggH_ACbis",nBins-1, array('d',[float(obs_bins[i]) for i in range(len(obs_bins))]) ) + for i in range(nBins-1): + h_ggH_ACbis.SetBinContent(i+1,v_ggH_ACbis[i]) + + h_ggH_powheg.SetLineColor(ROOT.kAzure+2) + h_ggH_powheg.SetLineWidth(2) + + if acFlag: + h_ggH_AC.SetLineColor(ROOT.kRed+2) + h_ggH_AC.SetLineWidth(2) + if acFlagBis: + h_ggH_ACbis.SetLineColor(ROOT.kViolet+2) + h_ggH_ACbis.SetLineWidth(2) + + + g_ggH_minloHJ = TGraphAsymmErrors(v_observable_2,v_ggH_minloHJ,v_dobservable_2,v_dobservable_2,v_ggH_minloHJ_unc_lo,v_ggH_minloHJ_unc_hi) + g_ggH_minloHJ.SetFillStyle(3245); + g_ggH_minloHJ.SetFillColor(ROOT.kOrange+2) + g_ggH_minloHJ.SetLineColor(ROOT.kOrange+2) + g_ggH_minloHJ.SetLineWidth(2) + g_ggH_minloHJ.SetMarkerColor(ROOT.kOrange+2) + + g_ggH_minloHJBorder = TGraphAsymmErrors(v_observable_2,v_ggH_minloHJ,v_dobservable_2,v_dobservable_2,v_ggH_minloHJ_unc_lo,v_ggH_minloHJ_unc_hi) + g_ggH_minloHJBorder.SetFillStyle(0) + g_ggH_minloHJBorder.SetFillColor(ROOT.kOrange+2) + g_ggH_minloHJBorder.SetLineColor(ROOT.kOrange+2) + g_ggH_minloHJBorder.SetMarkerColor(ROOT.kOrange+2) + + g_ggH_minloHJe0 = TGraphAsymmErrors(v_observable,v_ggH_minloHJ,v_dobservable,v_dobservable,v_zeros,v_zeros) + g_ggH_minloHJe0.SetFillStyle(3245); + g_ggH_minloHJe0.SetFillColor(ROOT.kOrange+2) + g_ggH_minloHJe0.SetLineColor(ROOT.kOrange+2) + g_ggH_minloHJe0.SetMarkerColor(ROOT.kOrange+2) + + if (obsName=="mass4l"): + h_ggH_minloHJ = TH1D("h_ggH_minloHJ","h_ggH_minloHJ",4, 0, 4) + for i in range(4): + h_ggH_minloHJ.SetBinContent(i+1,v_ggH_minloHJ[i]) + elif doubleDiff: + h_ggH_minloHJ = TH1D("h_ggH_minloHJ","h_ggH_minloHJ",nBins-1, 0, nBins-1) + for i in range(nBins-1): + h_ggH_minloHJ.SetBinContent(i+1,v_ggH_minloHJ[i]) + + g_ggH_minloHJ = TGraphAsymmErrors(v_observable_2,v_ggH_minloHJ,v_dobservable_2,v_dobservable_2,v_ggH_minloHJ_unc_lo,v_ggH_minloHJ_unc_hi) + g_ggH_minloHJ.SetFillStyle(3245); + g_ggH_minloHJ.SetFillColor(ROOT.kOrange+2) + g_ggH_minloHJ.SetLineColor(ROOT.kOrange+2) + g_ggH_minloHJ.SetLineWidth(2) + g_ggH_minloHJ.SetMarkerColor(ROOT.kOrange+2) + + g_ggH_minloHJBorder = TGraphAsymmErrors(v_observable_2,v_ggH_minloHJ,v_dobservable_2,v_dobservable_2,v_ggH_minloHJ_unc_lo,v_ggH_minloHJ_unc_hi) + g_ggH_minloHJBorder.SetFillStyle(0) + g_ggH_minloHJBorder.SetFillColor(ROOT.kOrange+2) + g_ggH_minloHJBorder.SetLineColor(ROOT.kOrange+2) + g_ggH_minloHJBorder.SetMarkerColor(ROOT.kOrange+2) + + if (not obsName =="mass4l" and not doubleDiff): + if ("jet" in obsName and (not obsName.startswith("njets"))): + h_ggH_minloHJ = TH1D("h_ggH_minloHJ","h_ggH_minloHJ",nBins-2, array('d',[float(obs_bins[i]) for i in range(1,len(obs_bins))]) ) + for i in range(1,nBins-1): + h_ggH_minloHJ.SetBinContent(i,v_ggH_minloHJ[i]) + else: + h_ggH_minloHJ = TH1D("h_ggH_minloHJ","h_ggH_minloHJ",nBins-1, array('d',[float(obs_bins[i]) for i in range(len(obs_bins))]) ) + for i in range(nBins-1): + h_ggH_minloHJ.SetBinContent(i+1,v_ggH_minloHJ[i]) + + h_ggH_minloHJ.SetLineColor(ROOT.kOrange+2) + h_ggH_minloHJ.SetLineWidth(2) + + + + ''' + g_ggH_HRes = TGraphAsymmErrors(v_observable,v_ggH_HRes,v_dobservable,v_dobservable,v_ggH_HRes_unc_lo,v_ggH_HRes_unc_hi) + g_ggH_HRes.SetFillStyle(3254); + g_ggH_HRes.SetFillColor(ROOT.kAzure+2) + g_ggH_HRes.SetLineColor(ROOT.kAzure+2) + g_ggH_HRes.SetLineWidth(2) + g_ggH_HRes.SetMarkerColor(ROOT.kAzure+2) + ''' + + g_XH = TGraphAsymmErrors(v_observable,v_XH,v_dobservable,v_dobservable,v_XH_lo,v_XH_hi) + g_XH.SetFillColor(ROOT.kGreen+3) + g_XH.SetLineColor(ROOT.kGreen+3) + + g_data = TGraphAsymmErrors(v_observable,v_data,v_zeros,v_zeros,v_data_lo,v_data_hi) + g_data.SetMarkerColor(ROOT.kBlack) + g_data.SetLineColor(ROOT.kBlack) + g_data.SetLineWidth(2) + g_data.SetMarkerStyle(20) + g_data.SetMarkerSize(1.4) + + g_data_e0 = TGraphAsymmErrors(v_observable,v_data,v_zeros,v_zeros,v_zeros,v_zeros) + g_data_e0.SetMarkerColor(ROOT.kBlack) + g_data_e0.SetLineColor(ROOT.kBlack) + g_data_e0.SetLineWidth(2) + g_data_e0.SetMarkerStyle(20) + g_data_e0.SetMarkerSize(1.4) + + # Ratio + if not acFlag: + v_ratio_data = TVectorD(len(data), array('d',[data[i]/ggH_minloHJ[i] for i in range(len(data))])) + v_ratio_data_hi = TVectorD(len(data), array('d',[data_hi[i]/ggH_minloHJ[i] for i in range(len(data))])) + v_ratio_data_lo = TVectorD(len(data), array('d',[data_lo[i]/ggH_minloHJ[i] for i in range(len(data))])) + + v_ratio_sys_hi = TVectorD(len(data), array('d',[systematics_hi[i]/ggH_minloHJ[i] for i in range(len(systematics_hi))])) + v_ratio_sys_lo = TVectorD(len(data), array('d',[systematics_lo[i]/ggH_minloHJ[i] for i in range(len(systematics_lo))])) + + v_ratio_minloHJ = TVectorD(len(ggH_minloHJ), array('d',[ggH_minloHJ[i]/ggH_minloHJ[i] for i in range(len(ggH_minloHJ))])) + v_ratio_minloHJ_hi = TVectorD(len(ggH_minloHJ), array('d',[ggH_minloHJ_NNLOunc_hi[i]/ggH_minloHJ[i] for i in range(len(ggH_minloHJ))])) + v_ratio_minloHJ_lo = TVectorD(len(ggH_minloHJ), array('d',[ggH_minloHJ_NNLOunc_lo[i]/ggH_minloHJ[i] for i in range(len(ggH_minloHJ))])) + + v_ratio_powheg = TVectorD(len(ggH_powheg), array('d',[ggH_powheg[i]/ggH_minloHJ[i] for i in range(len(ggH_powheg))])) + v_ratio_powheg_hi = TVectorD(len(ggH_powheg), array('d',[ggH_powheg_NLOunc_hi[i]/ggH_minloHJ[i] for i in range(len(ggH_powheg))])) + v_ratio_powheg_lo = TVectorD(len(ggH_powheg), array('d',[ggH_powheg_NLOunc_lo[i]/ggH_minloHJ[i] for i in range(len(ggH_powheg))])) + + g_ratio_data = TGraphAsymmErrors(v_observable,v_ratio_data,v_zeros,v_zeros,v_ratio_data_lo,v_ratio_data_hi) + g_ratio_data.SetMarkerColor(ROOT.kBlack) + g_ratio_data.SetLineColor(ROOT.kBlack) + g_ratio_data.SetLineWidth(2) + g_ratio_data.SetMarkerStyle(20) + g_ratio_data.SetMarkerSize(1.4) + + g_ratio_datae0 = TGraphAsymmErrors(v_observable,v_ratio_data,v_zeros,v_zeros,v_zeros,v_zeros) + g_ratio_datae0.SetMarkerColor(ROOT.kBlack) + g_ratio_datae0.SetLineColor(ROOT.kBlack) + g_ratio_datae0.SetLineWidth(2) + g_ratio_datae0.SetMarkerStyle(20) + g_ratio_datae0.SetMarkerSize(1.4) + + g_ratio_sys = TGraphAsymmErrors(v_observable,v_ratio_data,v_zeros,v_zeros,v_ratio_sys_lo,v_ratio_sys_hi) + g_ratio_sys.SetMarkerColor(ROOT.kRed) + g_ratio_sys.SetLineColor(ROOT.kRed) + g_ratio_sys.SetFillColor(ROOT.kRed) + g_ratio_sys.SetLineWidth(5) + + # g_ratio_powheg = TGraphAsymmErrors(v_observable_1,v_ratio_powheg,v_dobservable_1,v_dobservable_1,v_ratio_powheg_lo,v_ratio_powheg_hi) + # g_ratio_powheg.SetFillStyle(3254); + # g_ratio_powheg.SetFillColor(ROOT.kAzure+2) + # g_ratio_powheg.SetLineColor(ROOT.kAzure+2) + # g_ratio_powheg.SetLineWidth(2) + # g_ratio_powheg.SetMarkerColor(ROOT.kAzure+2) + # + # g_ratio_powhegBorder = TGraphAsymmErrors(v_observable_1,v_ratio_powheg,v_dobservable_1,v_dobservable_1,v_ratio_powheg_lo,v_ratio_powheg_hi) + # g_ratio_powhegBorder.SetFillStyle(0); + # g_ratio_powhegBorder.SetFillColor(ROOT.kAzure+2) + # g_ratio_powhegBorder.SetLineColor(ROOT.kAzure+2) + # g_ratio_powhegBorder.SetMarkerColor(ROOT.kAzure+2) + + g_ratio_powhege0 = TGraphAsymmErrors(v_observable,v_ratio_powheg,v_dobservable,v_dobservable,v_zeros,v_zeros) + g_ratio_powhege0.SetFillStyle(3254); + g_ratio_powhege0.SetFillColor(ROOT.kAzure+2) + g_ratio_powhege0.SetLineColor(ROOT.kAzure+2) + g_ratio_powhege0.SetLineWidth(2) + g_ratio_powhege0.SetMarkerColor(ROOT.kAzure+2) + + else: + v_ratio_data = TVectorD(len(data), array('d',[data[i]/ggH_powheg[i] for i in range(len(data))])) + v_ratio_data_hi = TVectorD(len(data), array('d',[data_hi[i]/ggH_powheg[i] for i in range(len(data))])) + v_ratio_data_lo = TVectorD(len(data), array('d',[data_lo[i]/ggH_powheg[i] for i in range(len(data))])) + + v_ratio_sys_hi = TVectorD(len(data), array('d',[systematics_hi[i]/ggH_powheg[i] for i in range(len(systematics_hi))])) + v_ratio_sys_lo = TVectorD(len(data), array('d',[systematics_lo[i]/ggH_powheg[i] for i in range(len(systematics_lo))])) + + v_ratio_AC = TVectorD(len(ggH_AC), array('d',[ggH_AC[i]/ggH_powheg[i] for i in range(len(ggH_AC))])) + v_ratio_AC_hi = TVectorD(len(ggH_AC), array('d',[ggH_AC_NLOunc_hi[i]/ggH_powheg[i] for i in range(len(ggH_AC))])) + v_ratio_AC_lo = TVectorD(len(ggH_AC), array('d',[ggH_AC_NLOunc_lo[i]/ggH_powheg[i] for i in range(len(ggH_AC))])) + if acFlagBis: + v_ratio_ACbis = TVectorD(len(ggH_ACbis), array('d',[ggH_ACbis[i]/ggH_powheg[i] for i in range(len(ggH_ACbis))])) + v_ratio_ACbis_hi = TVectorD(len(ggH_ACbis), array('d',[ggH_ACbis_NLOunc_hi[i]/ggH_powheg[i] for i in range(len(ggH_ACbis))])) + v_ratio_ACbis_lo = TVectorD(len(ggH_ACbis), array('d',[ggH_ACbis_NLOunc_lo[i]/ggH_powheg[i] for i in range(len(ggH_ACbis))])) + + v_ratio_powheg = TVectorD(len(ggH_powheg), array('d',[ggH_powheg[i]/ggH_powheg[i] for i in range(len(ggH_powheg))])) + v_ratio_powheg_hi = TVectorD(len(ggH_powheg), array('d',[ggH_powheg_NLOunc_hi[i]/ggH_powheg[i] for i in range(len(ggH_powheg))])) + v_ratio_powheg_lo = TVectorD(len(ggH_powheg), array('d',[ggH_powheg_NLOunc_lo[i]/ggH_powheg[i] for i in range(len(ggH_powheg))])) + + g_ratio_data = TGraphAsymmErrors(v_observable,v_ratio_data,v_zeros,v_zeros,v_ratio_data_lo,v_ratio_data_hi) + g_ratio_data.SetMarkerColor(ROOT.kBlack) + g_ratio_data.SetLineColor(ROOT.kBlack) + g_ratio_data.SetLineWidth(2) + g_ratio_data.SetMarkerStyle(20) + g_ratio_data.SetMarkerSize(1.4) + + g_ratio_datae0 = TGraphAsymmErrors(v_observable,v_ratio_data,v_zeros,v_zeros,v_zeros,v_zeros) + g_ratio_datae0.SetMarkerColor(ROOT.kBlack) + g_ratio_datae0.SetLineColor(ROOT.kBlack) + g_ratio_datae0.SetLineWidth(2) + g_ratio_datae0.SetMarkerStyle(20) + g_ratio_datae0.SetMarkerSize(1.4) + + g_ratio_sys = TGraphAsymmErrors(v_observable,v_ratio_data,v_zeros,v_zeros,v_ratio_sys_lo,v_ratio_sys_hi) + g_ratio_sys.SetMarkerColor(ROOT.kRed+2) + g_ratio_sys.SetLineColor(ROOT.kRed+2) + g_ratio_sys.SetFillColor(ROOT.kRed+2) + g_ratio_sys.SetLineWidth(5) + + # g_ratio_powheg = TGraphAsymmErrors(v_observable_1,v_ratio_powheg,v_dobservable_1,v_dobservable_1,v_ratio_powheg_lo,v_ratio_powheg_hi) + # g_ratio_powheg.SetFillStyle(3254); + # g_ratio_powheg.SetFillColor(ROOT.kAzure+2) + # g_ratio_powheg.SetLineColor(ROOT.kAzure+2) + # g_ratio_powheg.SetLineWidth(2) + # g_ratio_powheg.SetMarkerColor(ROOT.kAzure+2) + # + # g_ratio_powhegBorder = TGraphAsymmErrors(v_observable_1,v_ratio_powheg,v_dobservable_1,v_dobservable_1,v_ratio_powheg_lo,v_ratio_powheg_hi) + # g_ratio_powhegBorder.SetFillStyle(0); + # g_ratio_powhegBorder.SetFillColor(ROOT.kAzure+2) + # g_ratio_powhegBorder.SetLineColor(ROOT.kAzure+2) + # g_ratio_powhegBorder.SetMarkerColor(ROOT.kAzure+2) + + g_ratio_powhege0 = TGraphAsymmErrors(v_observable,v_ratio_powheg,v_dobservable,v_dobservable,v_zeros,v_zeros) + g_ratio_powhege0.SetFillStyle(3254); + g_ratio_powhege0.SetFillColor(ROOT.kAzure+2) + g_ratio_powhege0.SetLineColor(ROOT.kAzure+2) + g_ratio_powhege0.SetLineWidth(2) + g_ratio_powhege0.SetMarkerColor(ROOT.kAzure+2) + + if (obsName=="mass4l"): + g_ratio_powheg = TGraphAsymmErrors(v_observable_1,v_ratio_powheg,v_dobservable_1,v_dobservable_1,v_ratio_powheg_lo,v_ratio_powheg_hi) + g_ratio_powheg.SetFillStyle(3254); + g_ratio_powheg.SetFillColor(ROOT.kAzure+2) + g_ratio_powheg.SetLineColor(ROOT.kAzure+2) + g_ratio_powheg.SetLineWidth(2) + g_ratio_powheg.SetMarkerColor(ROOT.kAzure+2) + + g_ratio_powhegBorder = TGraphAsymmErrors(v_observable_1,v_ratio_powheg,v_dobservable_1,v_dobservable_1,v_ratio_powheg_lo,v_ratio_powheg_hi) + g_ratio_powhegBorder.SetFillStyle(0); + g_ratio_powhegBorder.SetFillColor(ROOT.kAzure+2) + g_ratio_powhegBorder.SetLineColor(ROOT.kAzure+2) + g_ratio_powhegBorder.SetMarkerColor(ROOT.kAzure+2) + + h_ratio_powheg = TH1D("h_ratio_powheg","h_ratio_powheg",4, 0, 4) + for i in range(4): + h_ratio_powheg.SetBinContent(i+1,v_ratio_powheg[i]) + elif doubleDiff: + g_ratio_powheg = TGraphAsymmErrors(v_observable_1,v_ratio_powheg,v_dobservable_1,v_dobservable_1,v_ratio_powheg_lo,v_ratio_powheg_hi) + g_ratio_powheg.SetFillStyle(3254); + g_ratio_powheg.SetFillColor(ROOT.kAzure+2) + g_ratio_powheg.SetLineColor(ROOT.kAzure+2) + g_ratio_powheg.SetLineWidth(2) + g_ratio_powheg.SetMarkerColor(ROOT.kAzure+2) + + g_ratio_powhegBorder = TGraphAsymmErrors(v_observable_1,v_ratio_powheg,v_dobservable_1,v_dobservable_1,v_ratio_powheg_lo,v_ratio_powheg_hi) + g_ratio_powhegBorder.SetFillStyle(0); + g_ratio_powhegBorder.SetFillColor(ROOT.kAzure+2) + g_ratio_powhegBorder.SetLineColor(ROOT.kAzure+2) + g_ratio_powhegBorder.SetMarkerColor(ROOT.kAzure+2) + + h_ratio_powheg = TH1D("h_ratio_powheg","h_ratio_powheg",5, 0, 5) + for i in range(5): + h_ratio_powheg.SetBinContent(i+1,v_ratio_powheg[i]) + else: + g_ratio_powheg = TGraphAsymmErrors(v_observable_1,v_ratio_powheg,v_dobservable_1,v_dobservable_1,v_ratio_powheg_lo,v_ratio_powheg_hi) + g_ratio_powheg.SetFillStyle(3254); + g_ratio_powheg.SetFillColor(ROOT.kAzure+2) + g_ratio_powheg.SetLineColor(ROOT.kAzure+2) + g_ratio_powheg.SetLineWidth(2) + g_ratio_powheg.SetMarkerColor(ROOT.kAzure+2) + + g_ratio_powhegBorder = TGraphAsymmErrors(v_observable_1,v_ratio_powheg,v_dobservable_1,v_dobservable_1,v_ratio_powheg_lo,v_ratio_powheg_hi) + g_ratio_powhegBorder.SetFillStyle(0); + g_ratio_powhegBorder.SetFillColor(ROOT.kAzure+2) + g_ratio_powhegBorder.SetLineColor(ROOT.kAzure+2) + g_ratio_powhegBorder.SetMarkerColor(ROOT.kAzure+2) + + if ("jet" in obsName and (not obsName.startswith("njets"))): + h_ratio_powheg = TH1D("h_ratio_powheg","h_ratio_powheg",nBins-2, array('d',[float(obs_bins[i]) for i in range(1,len(obs_bins))]) ) + for i in range(1,nBins-1): + h_ratio_powheg.SetBinContent(i,v_ratio_powheg[i]) + else: + h_ratio_powheg = TH1D("h_ratio_powheg","h_ratio_powheg",nBins-1, array('d',[float(obs_bins[i]) for i in range(len(obs_bins))]) ) + for i in range(nBins-1): + h_ratio_powheg.SetBinContent(i+1,v_ratio_powheg[i]) + + h_ratio_powheg.SetLineColor(ROOT.kAzure+2) + h_ratio_powheg.SetLineWidth(2) + + # g_ratio_minloHJ = TGraphAsymmErrors(v_observable_2,v_ratio_minloHJ,v_dobservable_2,v_dobservable_2,v_ratio_minloHJ_lo,v_ratio_minloHJ_hi) + # g_ratio_minloHJ.SetFillStyle(3245); + # g_ratio_minloHJ.SetFillColor(ROOT.kOrange+2) + # g_ratio_minloHJ.SetLineColor(ROOT.kOrange+2) + # g_ratio_minloHJ.SetLineWidth(2) + # g_ratio_minloHJ.SetMarkerColor(ROOT.kOrange+2) + # + # g_ratio_minloHJBorder = TGraphAsymmErrors(v_observable_2,v_ratio_minloHJ,v_dobservable_2,v_dobservable_2,v_ratio_minloHJ_lo,v_ratio_minloHJ_hi) + # g_ratio_minloHJBorder.SetFillStyle(0); + # g_ratio_minloHJBorder.SetFillColor(ROOT.kOrange+2) + # g_ratio_minloHJBorder.SetLineColor(ROOT.kOrange+2) + # g_ratio_minloHJBorder.SetMarkerColor(ROOT.kOrange+2) + + # g_ratio_minloHJe0 = TGraphAsymmErrors(v_observable,v_ratio_minloHJ,v_dobservable,v_dobservable,v_zeros,v_zeros) + # g_ratio_minloHJe0.SetFillStyle(3245); + # g_ratio_minloHJe0.SetFillColor(ROOT.kOrange+2) + # g_ratio_minloHJe0.SetLineColor(ROOT.kOrange+2) + # g_ratio_minloHJe0.SetLineWidth(2) + # g_ratio_minloHJe0.SetMarkerColor(ROOT.kOrange+2) + + if (obsName=="mass4l"): + + g_ratio_minloHJ = TGraphAsymmErrors(v_observable_2,v_ratio_minloHJ,v_dobservable_2,v_dobservable_2,v_ratio_minloHJ_lo,v_ratio_minloHJ_hi) + g_ratio_minloHJ.SetFillStyle(3245); + g_ratio_minloHJ.SetFillColor(ROOT.kOrange+2) + g_ratio_minloHJ.SetLineColor(ROOT.kOrange+2) + g_ratio_minloHJ.SetLineWidth(2) + g_ratio_minloHJ.SetMarkerColor(ROOT.kOrange+2) + + g_ratio_minloHJBorder = TGraphAsymmErrors(v_observable_2,v_ratio_minloHJ,v_dobservable_2,v_dobservable_2,v_ratio_minloHJ_lo,v_ratio_minloHJ_hi) + g_ratio_minloHJBorder.SetFillStyle(0); + g_ratio_minloHJBorder.SetFillColor(ROOT.kOrange+2) + g_ratio_minloHJBorder.SetLineColor(ROOT.kOrange+2) + g_ratio_minloHJBorder.SetMarkerColor(ROOT.kOrange+2) + + h_ratio_minloHJ = TH1D("h_ratio_minloHJ","h_ratio_minloHJ",4, 0, 4) + for i in range(4): + h_ratio_minloHJ.SetBinContent(i+1,v_ratio_minloHJ[i]) + elif doubleDiff: + + g_ratio_minloHJ = TGraphAsymmErrors(v_observable_2,v_ratio_minloHJ,v_dobservable_2,v_dobservable_2,v_ratio_minloHJ_lo,v_ratio_minloHJ_hi) + g_ratio_minloHJ.SetFillStyle(3245); + g_ratio_minloHJ.SetFillColor(ROOT.kOrange+2) + g_ratio_minloHJ.SetLineColor(ROOT.kOrange+2) + g_ratio_minloHJ.SetLineWidth(2) + g_ratio_minloHJ.SetMarkerColor(ROOT.kOrange+2) + + g_ratio_minloHJBorder = TGraphAsymmErrors(v_observable_2,v_ratio_minloHJ,v_dobservable_2,v_dobservable_2,v_ratio_minloHJ_lo,v_ratio_minloHJ_hi) + g_ratio_minloHJBorder.SetFillStyle(0); + g_ratio_minloHJBorder.SetFillColor(ROOT.kOrange+2) + g_ratio_minloHJBorder.SetLineColor(ROOT.kOrange+2) + g_ratio_minloHJBorder.SetMarkerColor(ROOT.kOrange+2) + + h_ratio_minloHJ = TH1D("h_ratio_minloHJ","h_ratio_minloHJ",5, 0, 5) + for i in range(5): + h_ratio_minloHJ.SetBinContent(i+1,v_ratio_minloHJ[i]) + elif acFlag: # We keep the same names as in the last else (just to reduce entropy with if statements) + g_ratio_minloHJ = TGraphAsymmErrors(v_observable_2,v_ratio_AC,v_dobservable_2,v_dobservable_2,v_ratio_AC_lo,v_ratio_AC_hi) + g_ratio_minloHJ.SetFillStyle(3245); + g_ratio_minloHJ.SetFillColor(ROOT.kRed+2) + g_ratio_minloHJ.SetLineColor(ROOT.kRed+2) + g_ratio_minloHJ.SetLineWidth(2) + g_ratio_minloHJ.SetMarkerColor(ROOT.kRed+2) + + g_ratio_minloHJBorder = TGraphAsymmErrors(v_observable_2,v_ratio_AC,v_dobservable_2,v_dobservable_2,v_ratio_AC_lo,v_ratio_AC_hi) + g_ratio_minloHJBorder.SetFillStyle(0); + g_ratio_minloHJBorder.SetFillColor(ROOT.kRed+2) + g_ratio_minloHJBorder.SetLineColor(ROOT.kRed+2) + g_ratio_minloHJBorder.SetMarkerColor(ROOT.kRed+2) + + if acFlagBis: + g_ratioBis_minloHJ = TGraphAsymmErrors(v_observable_2,v_ratio_ACbis,v_dobservable_2,v_dobservable_2,v_ratio_ACbis_lo,v_ratio_ACbis_hi) + g_ratioBis_minloHJ.SetFillStyle(3245); + g_ratioBis_minloHJ.SetFillColor(ROOT.kViolet+2) + g_ratioBis_minloHJ.SetLineColor(ROOT.kViolet+2) + g_ratioBis_minloHJ.SetLineWidth(2) + g_ratioBis_minloHJ.SetMarkerColor(ROOT.kViolet+2) + + g_ratioBis_minloHJBorder = TGraphAsymmErrors(v_observable_2,v_ratio_ACbis,v_dobservable_2,v_dobservable_2,v_ratio_ACbis_lo,v_ratio_ACbis_hi) + g_ratioBis_minloHJBorder.SetFillStyle(0); + g_ratioBis_minloHJBorder.SetFillColor(ROOT.kViolet+2) + g_ratioBis_minloHJBorder.SetLineColor(ROOT.kViolet+2) + g_ratioBis_minloHJBorder.SetMarkerColor(ROOT.kViolet+2) + + if ("jet" in obsName and (not obsName.startswith("njets"))): + h_ratio_minloHJ = TH1D("h_ratio_minloHJ","h_ratio_minloHJ",nBins-2, array('d',[float(obs_bins[i]) for i in range(1,len(obs_bins))]) ) + for i in range(1,nBins-1): + h_ratio_minloHJ.SetBinContent(i,v_ratio_AC[i]) + else: + h_ratio_minloHJ = TH1D("h_ratio_minloHJ","h_ratio_minloHJ",nBins-1, array('d',[float(obs_bins[i]) for i in range(len(obs_bins))]) ) + for i in range(nBins-1): + h_ratio_minloHJ.SetBinContent(i+1,v_ratio_AC[i]) + if acFlagBis: + h_ratioBis_minloHJ = TH1D("h_ratioBis_minloHJ","h_ratioBis_minloHJ",nBins-1, array('d',[float(obs_bins[i]) for i in range(len(obs_bins))]) ) + for i in range(nBins-1): + h_ratioBis_minloHJ.SetBinContent(i+1,v_ratio_ACbis[i]) + else: + g_ratio_minloHJ = TGraphAsymmErrors(v_observable_2,v_ratio_minloHJ,v_dobservable_2,v_dobservable_2,v_ratio_minloHJ_lo,v_ratio_minloHJ_hi) + g_ratio_minloHJ.SetFillStyle(3245); + g_ratio_minloHJ.SetFillColor(ROOT.kOrange+2) + g_ratio_minloHJ.SetLineColor(ROOT.kOrange+2) + g_ratio_minloHJ.SetLineWidth(2) + g_ratio_minloHJ.SetMarkerColor(ROOT.kOrange+2) + + g_ratio_minloHJBorder = TGraphAsymmErrors(v_observable_2,v_ratio_minloHJ,v_dobservable_2,v_dobservable_2,v_ratio_minloHJ_lo,v_ratio_minloHJ_hi) + g_ratio_minloHJBorder.SetFillStyle(0); + g_ratio_minloHJBorder.SetFillColor(ROOT.kOrange+2) + g_ratio_minloHJBorder.SetLineColor(ROOT.kOrange+2) + g_ratio_minloHJBorder.SetMarkerColor(ROOT.kOrange+2) + + if ("jet" in obsName and (not obsName.startswith("njets"))): + h_ratio_minloHJ = TH1D("h_ratio_minloHJ","h_ratio_minloHJ",nBins-2, array('d',[float(obs_bins[i]) for i in range(1,len(obs_bins))]) ) + for i in range(1,nBins-1): + h_ratio_minloHJ.SetBinContent(i,v_ratio_minloHJ[i]) + else: + h_ratio_minloHJ = TH1D("h_ratio_minloHJ","h_ratio_minloHJ",nBins-1, array('d',[float(obs_bins[i]) for i in range(len(obs_bins))]) ) + for i in range(nBins-1): + h_ratio_minloHJ.SetBinContent(i+1,v_ratio_minloHJ[i]) + + if not acFlag: h_ratio_minloHJ.SetLineColor(ROOT.kOrange+2) + else: + h_ratio_minloHJ.SetLineColor(ROOT.kRed+2) + if acFlagBis: + h_ratioBis_minloHJ.SetLineColor(ROOT.kViolet+2) + h_ratioBis_minloHJ.SetLineWidth(2) + h_ratio_minloHJ.SetLineWidth(2) + + g_modeldep = TGraphAsymmErrors(v_observable,v_data,v_twos,v_twos,v_modeldep_lo,v_modeldep_hi) + #g_modeldep = TGraphAsymmErrors(v_observable,v_data,v_twos,v_twos,v_modeldep_lo,v_modeldep_hi) + g_systematics = TGraphAsymmErrors(v_observable,v_data,v_zeros,v_zeros,v_systematics_lo,v_systematics_hi) + + #g_modeldep.SetLineWidth(5) + #g_modeldep.SetMarkerColor(ROOT.kGray) + g_modeldep.SetFillColor(ROOT.kBlack) + g_modeldep.SetLineColor(ROOT.kBlack) + + g_systematics.SetLineWidth(5) + g_systematics.SetMarkerColor(ROOT.kRed) + g_systematics.SetLineColor(ROOT.kRed) + g_systematics.SetFillColor(ROOT.kRed) + + g_data_allunc = TGraphAsymmErrors(v_observable,v_data,v_zeros,v_zeros,v_data_lo_allunc,v_data_hi_allunc) + g_data_allunc.SetMarkerColor(ROOT.kBlack) + g_data_allunc.SetLineColor(ROOT.kBlack) + g_data_allunc.SetLineWidth(1) + g_data_allunc.SetMarkerStyle(20) + g_data_allunc.SetMarkerSize(1.2) + + + if (obsName=="massZ2"): + label = "m(Z_{2})" + unit = "GeV" + elif (obsName=="massZ1"): + label = "m(Z_{1})" + unit = "GeV" + elif (obsName=="costhetastar"): + label = "|cos#theta*|" + unit = "" + elif (obsName=="costhetaZ1"): + label = "|cos#theta_{1}|" + unit = "" + elif (obsName=="costhetaZ2"): + label = "|cos#theta_{2}|" + unit = "" + elif (obsName=="phi"): + label = "|#Phi|" + unit = "" + elif (obsName=="phistar"): + label = "|#Phi_{1}|" + unit = "" + elif obsName=="D0m": + label = "D_{0-}^{dec}" + unit = "" + elif obsName=="D0hp": + label = "D_{0h+}^{dec}" + unit = "" + elif obsName=="Dcp": + label = "D_{CP}^{dec}" + unit = "" + elif obsName=="Dint": + label = "D_{int}^{dec}" + unit = "" + elif obsName=="DL1": + label = "D_{#Lambda 1}^{dec}" + unit = "" + else: + label = obsName + unit = "" + + label_2e2mu = label+'(2e2#mu)' + label_4l = label+'(4e+4#mu)' + + c = TCanvas("c",obsName, 1400, 1400) + if(opt.SETLOG): c.SetLogy() + if (not obsName=="mass4l"): c.SetBottomMargin(0.35) + c.SetRightMargin(0.04) + c.SetTopMargin(0.07) + c.SetLeftMargin(0.18) + + if (obsName=="mass4l"): + dummy = TH1D("dummy","dummy", 4, 0, 4) + for i in range(1,5): + dummy.SetBinContent(i,2.5*max(a_ggH_powheg)) + h_XH = TH1D("h_XH","h_XH",4, 0, 4) + print "mass4l",a_XH + for i in range(4): + h_XH.SetBinContent(i+1,a_XH[i]) + elif doubleDiff: + dummy = TH1D("dummy","dummy", nBins-1, 0, nBins-1) + for i in range(1,nBins-1): + dummy.SetBinContent(i,2.5*max(a_ggH_powheg)) + h_XH = TH1D("h_XH","h_XH",nBins-1, 0, nBins-1) + print "mass4l",a_XH + for i in range(nBins-1): + h_XH.SetBinContent(i+1,a_XH[i]) + else: + if ("jet" in obsName and (not obsName.startswith("njets"))): + dummy = TH1D("dummy","dummy", int(float(obs_bins[nBins-1])-float(obs_bins[1])), float(obs_bins[1]), float(obs_bins[nBins-1])) + for i in range(int(float(obs_bins[nBins-1])-float(obs_bins[1]))): + dummy.SetBinContent(i,2.5*max(a_ggH_powheg)) + #h_XH = TH1D("h_XH","h_XH",nBins-1, array('d',[float(obs_bins[i]) for i in range(len(obs_bins))]) ) + #for i in range(nBins-1): + # h_XH.SetBinContent(i+1,a_XH[i]) + h_XH = TH1D("h_XH","h_XH",nBins-2, array('d',[float(obs_bins[i]) for i in range(1,len(obs_bins))]) ) + for i in range(1,nBins-1): + h_XH.SetBinContent(i,a_XH[i]) + else: + dummy = TH1D("dummy","dummy", int(float(obs_bins[nBins-1])-float(obs_bins[0])), float(obs_bins[0]), float(obs_bins[nBins-1])) + for i in range(int(float(obs_bins[nBins-1])-float(obs_bins[0]))): + dummy.SetBinContent(i,2.5*max(a_ggH_powheg)) + h_XH = TH1D("h_XH","h_XH",nBins-1, array('d',[float(obs_bins[i]) for i in range(len(obs_bins))]) ) + for i in range(nBins-1): + h_XH.SetBinContent(i+1,a_XH[i]) + + if(opt.SETLOG): + if (obsName=="massZ2"): dummy.SetMaximum(500.0*max(max(a_data),(max(a_ggH_powheg)))) #AT + elif (obsName=="massZ1"): dummy.SetMaximum(500.0*max(max(a_data),(max(a_ggH_powheg)))) #AT + elif doubleDiff: dummy.SetMaximum(300*max(max(a_data),(max(a_ggH_powheg)))) + elif (obsName=="D0m"): dummy.SetMaximum(1100*max(max(a_data),(max(a_ggH_powheg)))) + elif (obsName=="Dcp"): dummy.SetMaximum(1100*max(max(a_data),(max(a_ggH_powheg)))) + elif (obsName=="D0hp"): dummy.SetMaximum(1100*max(max(a_data),(max(a_ggH_powheg)))) + elif (obsName=="DL1"): dummy.SetMaximum(1100*max(max(a_data),(max(a_ggH_powheg)))) + else: dummy.SetMaximum(55.0*max(max(a_data),(max(a_ggH_powheg)))) + else: + if (obsName=="mass4l") or doubleDiff: dummy.SetMaximum(1.6*(max(max(a_data),(max(a_ggH_powheg)))+max(a_data_hi))) + if doubleDiff: dummy.SetMaximum(2.0*(max(max(a_data),(max(a_ggH_powheg)))+max(a_data_hi))) + elif (obsName=="massZ2"): dummy.SetMaximum(2.0*(max(max(a_data),(max(a_ggH_powheg)))+max(a_data_hi))) #AT + elif (obsName=="massZ1"): dummy.SetMaximum(2.0*(max(max(a_data),(max(a_ggH_powheg)))+max(a_data_hi))) #AT + elif (obsName=="D0m"): dummy.SetMaximum(2.0*(max(max(a_data),(max(a_ggH_powheg)))+max(a_data_hi))) #AT + elif (obsName=="Dcp"): dummy.SetMaximum(2.0*(max(max(a_data),(max(a_ggH_powheg)))+max(a_data_hi))) #AT + elif (obsName=="D0hp"): dummy.SetMaximum(2.5*(max(max(a_data),(max(a_ggH_powheg)))+max(a_data_hi))) #AT + elif (obsName=="DL1"): dummy.SetMaximum(2.8*max(max(a_data),(max(a_ggH_powheg)))) + else: dummy.SetMaximum(1.5*(max(max(a_ggH_powheg),(max(a_data)+max(a_data_hi))))) + if (opt.SETLOG): + dummy.SetMinimum(0.0601*max(min(a_data),(min(a_ggH_powheg)))) + if (obsName.startswith("pTj1")): dummy.SetMinimum(0.0801*max(min(a_data),(min(a_ggH_powheg)))) + else: dummy.SetMinimum(0.0001) + dummy.SetLineColor(0) + dummy.SetMarkerColor(0) + dummy.SetLineWidth(0) + dummy.SetMarkerSize(0) + dummy.GetXaxis().SetLabelSize(0.0) + dummy.GetYaxis().SetLabelSize(0.04) + if (opt.SETLOG and (obsName.startswith('njets') or obsName.startswith('pTj1'))): + dummy.SetMaximum(200.0*max(max(a_data),(max(a_ggH_powheg)))) + dummy.GetXaxis().SetTitle("") + else: + dummy.GetXaxis().SetTitle("") + if (obsName.startswith('njets')): + dummy.GetXaxis().SetTitle('') + dummy.GetXaxis().SetLabelSize(0.0) + dummy.GetXaxis().SetBinLabel(1,'') + dummy.GetXaxis().SetBinLabel(2,'') + dummy.GetXaxis().SetBinLabel(3,'') + dummy.GetXaxis().SetBinLabel(4,'') + if (obsName=="mass4l"): + dummy.GetXaxis().SetLabelSize(0.08) + dummy.GetXaxis().SetBinLabel(1,'4l') + dummy.GetXaxis().SetBinLabel(2,'2e2#mu') + dummy.GetXaxis().SetBinLabel(3,'4#mu') + dummy.GetXaxis().SetBinLabel(4,'4e') + if doubleDiff: + dummy.GetXaxis().SetLabelSize(0.08) + dummy.GetXaxis().SetTitle('') + for i in range(1,nBins-1): + dummy.GetXaxis().SetBinLabel(i,'') + # dummy.GetXaxis().SetBinLabel(1,'') + # dummy.GetXaxis().SetBinLabel(2,'') + # dummy.GetXaxis().SetBinLabel(3,'') + # dummy.GetXaxis().SetBinLabel(4,'') + # dummy.GetXaxis().SetBinLabel(5,'') + + dummy.GetXaxis().SetTitleSize(0.0) + + if (label=="inclusive"): + dummy.GetYaxis().SetTitle("#sigma_{fid} (fb)") + elif (unit==''): + dummy.GetYaxis().SetTitle("d#sigma_{fid }/d"+label+" (fb)") + elif doubleDiff: + if unit==unit_2nd: + dummy.GetYaxis().SetTitle("d^{2}#sigma_{fid }/d"+label+"d"+label_2nd+" (fb/"+unit+"^{2})") + else: + dummy.GetYaxis().SetTitle("d^{2}#sigma_{fid }/d"+label+"d"+label_2nd+" (fb/"+unit+unit_2nd+")") + dummy.GetYaxis().SetTitleSize(0.04) + else: + dummy.GetYaxis().SetTitle("d#sigma_{fid }/d"+label+" (fb/"+unit+")") + if (obsName.startswith('njets')): + dummy.GetYaxis().SetTitle("#sigma_{fid} (fb)") + + dummy.GetYaxis().SetTitleOffset(1.4) + #dummy.GetYaxis().SetTitleOffset(1.8) + dummy.Draw("hist") + + h_XH.SetFillColor(kGreen-8) + h_XH.SetFillStyle(3344) + + legend = TLegend(.28,.65,.85,.90) + #legend . SetNColumns(2) + #legend . SetTextSize(0.026) + #legend . SetTextSize(0.029) # less info for XH + legend . SetTextSize(0.025) # shrink margins + if (opt.UNBLIND): legend . AddEntry(g_data , "Data (stat. #oplus sys. unc.)", "ep") + #else: legend . AddEntry(g_data , "Asimov Data (stat.#oplussys. unc.)", "ep") + else: legend . AddEntry(g_data , "Toy Data (stat. #oplus sys. unc.)", "ep") + legend . AddEntry(g_systematics,"Systematic uncertainty","l") + # legend . AddEntry(g_modeldep,"Model dependence","f") + if not acFlag: + legend . AddEntry(g_ggH_minloHJ , "gg#rightarrowH (NNLOPS + JHUGen) + XH", "lf") + legend . AddEntry(g_ggH_powheg , "gg#rightarrowH (POWHEG + JHUGen) + XH", "lf") + else: + legend . AddEntry(g_ggH_powheg , "SM (POWHEG + JHUGen + Pythia)", "lf") + if (obsName=="D0m"): legend . AddEntry(g_ggH_AC , "AC (POWHEG + JHUGen fa3=1 + Pythia)", "lf") + if (obsName=="Dcp"): legend . AddEntry(g_ggH_AC , "AC (POWHEG + JHUGen fa3=0.5 + Pythia)", "lf") + if (obsName=="Dint"): legend . AddEntry(g_ggH_AC , "AC (POWHEG + JHUGen fa2=0.5 + Pythia)", "lf") + if (obsName=="D0hp"): legend . AddEntry(g_ggH_AC , "AC (POWHEG + JHUGen fa2=1 + Pythia)", "lf") + if (obsName=="DL1"): + legend . AddEntry(g_ggH_AC , "AC (POWHEG + JHUGen faL1=1 + Pythia)", "lf") + legend . AddEntry(g_ggH_ACbis , "AC (POWHEG + JHUGen faL1=0.5 + Pythia)", "lf") + #legend . AddEntry(g_XH , "XH = VBF + VH + ttH", "l") + if not acFlag: legend . AddEntry(h_XH , "XH = VBF + VH + ttH (POWHEG + JHUGen)", "f") + legend . AddEntry(dummy, "(LHCHWG YR4, m_{H}="+opt.THEORYMASS+" GeV)", "") + + legend.SetShadowColor(0); + legend.SetFillColor(0); + legend.SetLineColor(0); + legend.Draw() + + + h_ggH_powheg.Draw("histsame") + if acFlag: + h_ggH_AC.Draw("histsame") + if acFlagBis: + h_ggH_ACbis.Draw("histsame") + else: h_ggH_minloHJ.Draw("histsame") + g_ggH_powheg.Draw("5same") + g_ggH_powhegBorder.Draw("5same") + #g_ggH_powhege0.Draw("epsame") + if acFlag: + g_ggH_AC.Draw("5same") + g_ggH_ACBorder.Draw("5same") + if acFlagBis: + g_ggH_ACbis.Draw("5same") + g_ggH_ACbisBorder.Draw("5same") + else: + g_ggH_minloHJ.Draw("5same") + g_ggH_minloHJBorder.Draw("5same") + #g_ggH_minloHJe0.Draw("epsame") + + #g_XH.Draw("2same") + #g_XH.Draw("fsame") + if not acFlag: h_XH.Draw("histsame") + # g_modeldep.Draw("2same0") + # g_modeldep.Draw("psame") + g_data.Draw("psameZ0") + g_systematics.Draw("psameZ0") + g_data_e0.Draw("psame") + + latex2 = TLatex() + latex2.SetNDC() + latex2.SetTextSize(0.5*c.GetTopMargin()) + latex2.SetTextFont(42) + latex2.SetTextAlign(31) # align right + # print opt.LUMISCALE + # if (not opt.LUMISCALE=="1.0"): + # lumi = round(137.1*float(opt.LUMISCALE),1) + # latex2.DrawLatex(0.94, 0.94,str(lumi)+" fb^{-1} (13 TeV)") + # else: + if(opt.YEAR=='2016'): + latex2.DrawLatex(0.92, 0.95,"35.9 fb^{-1} (13 TeV)") + if(opt.YEAR=='2017'): + latex2.DrawLatex(0.92, 0.95,"41.5 fb^{-1} (13 TeV)") + if(opt.YEAR=='2018'): + latex2.DrawLatex(0.92, 0.95,"59.7 fb^{-1} (13 TeV)") + if(opt.YEAR=='Full'): + latex2.DrawLatex(0.92, 0.95,"137 fb^{-1} (13 TeV)") + latex2.SetTextSize(0.7*c.GetTopMargin()) + latex2.SetTextFont(62) + latex2.SetTextAlign(11) # align right + latex2.DrawLatex(0.19, 0.94, "CMS #bf{#it{Preliminary}}") #AT Tolta scritta CMS + latex2.SetTextSize(0.6*c.GetTopMargin()) + latex2.SetTextFont(52) + latex2.SetTextAlign(11) + #latex2.DrawLatex(0.28, 0.945, "Unpublished") + #latex2.DrawLatex(0.30, 0.94, "Preliminary") + + latex2.SetTextSize(0.4*c.GetTopMargin()) + latex2.SetTextFont(42) + latex2.SetTextAlign(31) # align right + #latex2.DrawLatex(0.55, 0.67,"N^{3}LO #sigma_{gg#rightarrowH}^{total}") + + if ("2p5" in obsName): + latex2.SetTextSize(0.4*c.GetTopMargin()) + latex2.SetTextFont(42) + latex2.SetTextAlign(31) # align right + latex2.DrawLatex(0.92, 0.61,"p_{T}(jet) > 30 GeV, |#eta(jet)| < 2.5") + if ("4p7" in obsName): + latex2.SetTextSize(0.4*c.GetTopMargin()) + latex2.SetTextFont(42) + latex2.SetTextAlign(31) # align right + latex2.DrawLatex(0.92, 0.61,"p_{T}(jet) > 30 GeV, |#eta(jet)| < 4.7") + + if (obsName=="pT4l"): + latex2.SetTextSize(0.35*c.GetTopMargin()) + latex2.SetTextFont(42) + latex2.SetTextAlign(31) # align right + latex2.SetTextAngle(90) + latex2.DrawLatex(0.92, 0.77,"#frac{1}{50} #sigma(p_{T}(H) > 200 GeV)") + + + + dummy.Draw("axissame") + + if (not obsName=="mass4l"): + pad = TPad("pad", "pad", 0.0, 0.0, 1.0, 1.0) + pad.SetTopMargin(0.65) + pad.SetRightMargin(0.04) + pad.SetLeftMargin(0.18) + pad.SetFillColor(0) + pad.SetGridy(1) + pad.SetFillStyle(0) + pad.Draw() + pad.cd(0) + + if (obsName=="mass4l"): + dummy2 = TH1D("dummy2","dummy2", 4, 0, 4) + for i in range(1,5): + dummy2.SetBinContent(i,1.02) + dummy2.GetXaxis().SetLabelSize(0.08) + dummy2.GetXaxis().SetBinLabel(1,'4l') + dummy2.GetXaxis().SetBinLabel(2,'2e2#mu') + dummy2.GetXaxis().SetBinLabel(3,'4#mu') + dummy2.GetXaxis().SetBinLabel(4,'4e') + elif doubleDiff: + dummy2 = TH1D("dummy2","dummy2", nBins-1, 0, nBins-1) + for i in range(1,nBins-1): + dummy2.SetBinContent(i,1.02) + dummy2.GetXaxis().SetTitle("") + dummy2.GetXaxis().SetLabelSize(0.08) + for i in range(1,nBins): + dummy2.GetXaxis().SetBinLabel(i,'Bin '+str(i-1)) + # dummy2.GetXaxis().SetBinLabel(1,'0') + # dummy2.GetXaxis().SetBinLabel(2,'1') + # dummy2.GetXaxis().SetBinLabel(3,'2') + # dummy2.GetXaxis().SetBinLabel(4,'3') + # dummy2.GetXaxis().SetBinLabel(5,'4') + else: + if ("jet" in obsName and (not obsName.startswith("njets"))): + dummy2 = TH1D("dummy2","dummy2", int(float(obs_bins[nBins-1])-float(obs_bins[1])), float(obs_bins[1]), float(obs_bins[nBins-1])) + for i in range(int(float(obs_bins[nBins-1])-float(obs_bins[1]))): + dummy2.SetBinContent(i,1.02) + else: + if (obsName=="pT4l"): + dummy2 = TH1D("dummy2","dummy2", int(float(obs_bins[nBins-1])-float(obs_bins[0])), float(obs_bins[0]), float(obs_bins[nBins-1])) + else: + dummy2 = TH1D("dummy2","dummy2", int(float(obs_bins[nBins-1])-float(obs_bins[0])), float(obs_bins[0]), float(obs_bins[nBins-1])) + for i in range(int(float(obs_bins[nBins-1])-float(obs_bins[0]))): + dummy2.SetBinContent(i,1.02) + if doubleDiff:dummy2.GetXaxis().SetLabelSize(0.08) + else: dummy2.GetXaxis().SetLabelSize(0.04) + + dummy2.SetLineColor(0) + dummy2.SetMarkerColor(0) + dummy2.SetLineWidth(0) + dummy2.SetMarkerSize(0) + if (obsName.startswith('njets')): + dummy2.GetXaxis().SetTitle(label) + dummy2.GetXaxis().SetLabelSize(0.08) + dummy2.GetXaxis().SetBinLabel(1,'0') + dummy2.GetXaxis().SetBinLabel(2,'1') + dummy2.GetXaxis().SetBinLabel(3,'2') + dummy2.GetXaxis().SetBinLabel(4,' 3') + dummy2.GetXaxis().SetBinLabel(5,'#geq 4') + # elif (label=="inclusive"): + # dummy2.GetXaxis().SetTitle("") + # elif (unit==""): + # dummy2.GetXaxis().SetTitle(label) + # elif doubleDiff: + # dummy2.GetXaxis().SetTitle("") + # else: + # dummy2.GetXaxis().SetTitle(label+" ("+unit+")") + if chan == '4l': + dummy2.GetXaxis().SetTitle(label_4l) + else: + dummy2.GetXaxis().SetTitle(label_2e2mu) + + + dummy2.GetYaxis().SetLabelSize(0.03) + dummy2.GetYaxis().SetNdivisions(10); + if (obsName.startswith("pTj1")): dummy2.GetYaxis().SetNdivisions(8); + dummy2.GetXaxis().SetNdivisions(510) + ratiomax=1.0 + for i in range(len(data_hi)): + if ((data[i]+data_hi[i])/ggH_minloHJ[i]>ratiomax): ratiomax=(data[i]+data_hi[i])/ggH_minloHJ[i] + dummy2.SetMaximum(ratiomax*1.1) + if (obsName=="pT4l"): + dummy2.SetMaximum(ratiomax*1.04) + dummy2.GetYaxis().SetNdivisions(508) + dummy2.SetMinimum(0.0) + dummy2.Draw("hist") + dummy2.GetYaxis().CenterTitle() + dummy2.GetYaxis().SetTitleSize(0.04) + dummy2.GetYaxis().SetTitleOffset(1.5) + dummy2.GetYaxis().SetTitleSize(0.03) + dummy2.GetYaxis().SetTitleOffset(2.0) + if acFlag: dummy2.GetYaxis().SetTitle('Ratio to SM') + else: dummy2.GetYaxis().SetTitle('Ratio to NNLOPS') + + + h_ratio_powheg.Draw("histsame") + h_ratio_minloHJ.Draw("histsame") + if acFlagBis: h_ratioBis_minloHJ.Draw("histsame") + + g_ratio_minloHJ.Draw("5same") + g_ratio_minloHJBorder.Draw("5same") + if acFlagBis: + g_ratioBis_minloHJ.Draw("5same") + g_ratioBis_minloHJBorder.Draw("5same") + #g_ratio_minloHJe0.Draw("epsame") + + g_ratio_powheg.Draw("5same") + g_ratio_powhegBorder.Draw("5same") + #g_ratio_powhege0.Draw("epsame") + + g_ratio_data.Draw("psameZ0") + g_ratio_sys.Draw("psameZ0") + g_ratio_datae0.Draw("psame") + + dummy2.GetYaxis().SetRangeUser(0,3) + dummy2.Draw("axissame") + + if (obsName=="pT4l"): + box = TPaveText(240,-0.4,260,-0.1) + box.SetLineColor(0) + box.SetFillColor(0) + box.AddText(" ") + box.Draw("same") + + #if (opt.SETLOG): set_log = '_HResTESTlogscale' + #else: set_log = 'HResTEST' + + if (opt.SETLOG): set_log = '_logscale' + else: set_log = '' + + if (not opt.UNBLIND): set_log = set_log + '_asimov' + + if (opt.UNBLIND): subdir = 'data' + elif(not opt.UNBLIND): subdir = 'asimov' + + checkDir('plots/'+obsName) + checkDir('plots/'+obsName+'/'+subdir) + + c.SaveAs('plots/'+obsName+'/'+subdir+'/'+obsName+'_unfoldwith_'+chan+'_'+datamodel+set_log+'.pdf') + c.SaveAs('plots/'+obsName+'/'+subdir+'/'+obsName+'_unfoldwith_'+chan+'_'+datamodel+set_log+'.png') + c.SaveAs('plots/'+obsName+'/'+subdir+'/'+obsName+'_unfoldwith_'+chan+'_'+datamodel+set_log+'.root') + c.SaveAs('plots/'+obsName+'/'+subdir+'/'+obsName+'_unfoldwith_'+chan+'_'+datamodel+set_log+'.C') + #c.SaveAs('plots/'+obsName+'_unfoldwith_'+datamodel+set_log+'_unpublished.pdf') + #c.SaveAs('plots/'+obsName+'_unfoldwith_'+datamodel+set_log+'_unpublished.png') + #c.SaveAs('plots/'+obsName+'_unfoldwith_'+datamodel+set_log+'_unpublished.root') + #c.SaveAs('plots/'+obsName+'_unfoldwith_'+datamodel+set_log+'_unpublished.C') + #c.SaveAs('plots/'+obsName+'_unfoldwith_'+datamodel+set_log+'_preliminary.pdf') + #c.SaveAs('plots/'+obsName+'_unfoldwith_'+datamodel+set_log+'_preliminary.png') + #c.SaveAs('plots/'+obsName+'_unfoldwith_'+datamodel+set_log+'_preliminary.root') + #c.SaveAs('plots/'+obsName+'_unfoldwith_'+datamodel+set_log+'_preliminary.C') + # with open('table/table_'+opt.OBSNAME+'_'+subdir+'.py', 'w') as f: + # f.write('\\documentclass{article} \n') + # f.write('\\begin{document} \n') + # f.write('\\begin{table}[!h!tb] \n') + # f.write('\\begin{center} \n') + # f.write('\\begin{tabular}{|l|') + # for columns in range(0,len(obs_bins)-1): + # f.write('c|') + # f.write('} \\hline \\hline \n') + # f.write('Observable & ' ) + # for obsbin in range(0,len(obs_bins)-1): + # f.write('$'+obs_bins[obsbin]+'-'+obs_bins[obsbin+1]+'$') + # if (obsbin == len(obs_bins)-2): + # f.write(' \\\\ \\hline \n') + # else: + # f.write (' & ') + # f.write(opt.OBSNAME+' & \n') + # rbin =0 + # for obsbin in range(0,len(obs_bins)-1): + # f.write('$'+str(round(a_data[obsbin],3))+'^{+'+str(abs(round(sqrt(a_data_hi[obsbin]**2-a_systematics_hi[obsbin]**2),3)))+'+'+str(abs(round(a_systematics_hi[obsbin],3)))+'}'+'_{-'+str(abs(round(sqrt(a_data_lo[obsbin]**2-a_systematics_lo[obsbin]**2),3)))+'-'+str(abs(round(a_systematics_lo[obsbin],3)))+'}$') + # if (obsbin == len(obs_bins)-2): + # f.write (' \n ') + # else: + # f.write (' & ') + # f.write(' \\\\ \\hline \n') + # f.write('\\end{tabular} \n') + # f.write('\\end{center} \n') + # f.write('\\end{table} \n') + # f.write('\\end{document} \n') +doubleDiff = False +obs_name = opt.OBSNAME +if 'vs' in opt.OBSNAME: + doubleDiff = True + obs_name_tmp = opt.OBSNAME.split(' vs ') + obs_name = obs_name_tmp[0]+'_'+obs_name_tmp[1] + +_temp = __import__('inputs_sig_'+obs_name+'_'+opt.YEAR, globals(), locals(), ['observableBins'], -1) +obs_bins = _temp.observableBins +print(obs_bins) + +if obs_name == 'D0m': + acFlag = True + acFlagBis = False + acSample = '0M' +elif obs_name == 'Dcp': + acFlag = True + acFlagBis = False + acSample = '0Mf05ph0' +elif obs_name == 'D0hp': + acFlag = True + acFlagBis = False + acSample = '0PH' +elif obs_name == 'Dint': + acFlag = True + acFlagBis = False + acSample = '0PHf05ph0' +elif obs_name == 'DL1': + acFlag = True + acFlagBis = True + acSample = '0L1' + acSampleBis = '0L1f05ph0' +else: + acFlag = False + acFlagBis = False + +if not doubleDiff: + if float(obs_bins[len(obs_bins)-1])>300.0: + obs_bins[len(obs_bins)-1]='250.0' + if (opt.OBSNAME=="nJets" or opt.OBSNAME.startswith("njets")): + obs_bins[len(obs_bins)-1]='5' +else: + obs_bins_boundaries = obs_bins + obs_bins = [i for i in range(len(obs_bins)+1)] + +print('obs_bins', obs_bins) +for c in ['4l', '2e2mu']: + if doubleDiff: plotXS(obs_name, obs_bins, obs_bins_boundaries, c) + # else: plotXS(obs_name, obs_bins) + else: plotXS(obs_name, obs_bins, c) +sys.path.remove('./inputs') +sys.path.remove('./LHScans') diff --git a/templates/RunTemplates.py b/templates/RunTemplates.py index 963949a..d5955dd 100644 --- a/templates/RunTemplates.py +++ b/templates/RunTemplates.py @@ -3,17 +3,19 @@ import os, sys import numpy as np import pandas as pd -import uproot +import uproot3 as uproot from math import sqrt, log import itertools import optparse import math import ROOT import json -from tdrStyle import * +# from tdrStyle import * import random #-*-*-*-*-*-*-*-*-*-*-*-* Temporary - since we do not have discriminantsa in data yet, we perform a random generation -*-*-*-*-*-*-*-*-*-*-*-* +from binning import binning +from paths import path -sys.path.append('../inputs/') +# sys.path.append('../inputs/') # from observables import observables print 'Welcome in RunTemplates!' @@ -36,9 +38,9 @@ def parseOptions(): global opt, args (opt, args) = parser.parse_args() - if (opt.OBSBINS=='' and opt.OBSNAME!='inclusive'): - parser.error('Bin boundaries not specified for differential measurement. Exiting...') - sys.exit() + # if (opt.OBSBINS=='' and opt.OBSNAME!='inclusive'): + # parser.error('Bin boundaries not specified for differential measurement. Exiting...') + # sys.exit() # parse the arguments and options @@ -159,7 +161,7 @@ def dataframes(year): 'overallEventWeight', 'L1prefiringWeight', 'JetPt', 'JetEta', 'costhetastar', 'helcosthetaZ1','helcosthetaZ2','helphi','phistarZ1', 'pTHj', 'TCjmax', 'TBjmax', 'mjj', 'pTj1', 'pTj2', 'mHj', 'mHjj', 'pTHjj', - 'njets_pt30_eta4p7', + 'njets_pt30_eta4p7', 'absdetajj', 'Dcp', 'D0m', 'D0hp', 'Dint', 'DL1', 'DL1int', 'DL1Zg', 'DL1Zgint'] if (bkg == 'ZZTo4lext') | (bkg == 'ZZTo4lext1'): b_bkg.append('KFactor_EW_qqZZ'); b_bkg.append('KFactor_QCD_qqZZ_M') @@ -319,7 +321,7 @@ def doZX(year): # ------------------------------- FUNCTIONS FOR TEMPLATES ---------------------------------------------------- def smoothAndNormaliseTemplate(h1d, norm): #smooth - h1d.Smooth()#10000) + h1d.Smooth(10000) #norm + floor + norm #normaliseHist(h1d, norm) fillEmptyBinsHist(h1d,.01/(h1d.GetNbinsX())) @@ -337,6 +339,7 @@ def fillEmptyBinsHist(h1d, floor): def doTemplates(df_irr, df_red, binning, var, var_string, var_2nd='None'): for year in years: + checkDir(str(year)) checkDir(str(year)+"/"+var_string) fractionBkg = {} nBins = len(obs_bins) @@ -344,7 +347,6 @@ def doTemplates(df_irr, df_red, binning, var, var_string, var_2nd='None'): # qqzz and ggzz for bkg in ['qqzz', 'ggzz']: for f in ['2e2mu', '4e', '4mu']: - #df = df_irr[year][bkg][(df_irr[year][bkg].FinState == f) & (df_irr[year][bkg].Z2Mass < 60) & (df_irr[year][bkg].ZZMass >= 105) & (df_irr[year][bkg].ZZMass <= 160)].copy() df = df_irr[year][bkg][(df_irr[year][bkg].FinState == f) & (df_irr[year][bkg].ZZMass >= opt.LOWER_BOUND) & (df_irr[year][bkg].ZZMass <= opt.UPPER_BOUND)].copy() len_tot = df['weight'].sum() # Total number of bkg b events in final state f yield_bkg[year,bkg,f] = len_tot @@ -371,6 +373,20 @@ def doTemplates(df_irr, df_red, binning, var, var_string, var_2nd='None'): sel = sel_bin_low & sel_bin_high & sel_bin_mass_low & sel_bin_mass_high & sel_fstate if doubleDiff: sel &= sel_bin_2nd_low & sel_bin_2nd_high + if 'zzfloating' in obs_name: + df_2016_qqzz = df_irr[2016]['qqzz'][(df_irr[2016]['qqzz'].ZZMass >= opt.LOWER_BOUND) & (df_irr[2016]['qqzz'].ZZMass <= opt.UPPER_BOUND) & (df_irr[2016]['qqzz'][var] >= bin_low) & (df_irr[2016]['qqzz'][var] < bin_high)].copy() + df_2017_qqzz = df_irr[2017]['qqzz'][(df_irr[2017]['qqzz'].ZZMass >= opt.LOWER_BOUND) & (df_irr[2017]['qqzz'].ZZMass <= opt.UPPER_BOUND) & (df_irr[2017]['qqzz'][var] >= bin_low) & (df_irr[2017]['qqzz'][var] < bin_high)].copy() + df_2018_qqzz = df_irr[2018]['qqzz'][(df_irr[2018]['qqzz'].ZZMass >= opt.LOWER_BOUND) & (df_irr[2018]['qqzz'].ZZMass <= opt.UPPER_BOUND) & (df_irr[2018]['qqzz'][var] >= bin_low) & (df_irr[2018]['qqzz'][var] < bin_high)].copy() + df_2016_ggzz = df_irr[2016]['ggzz'][(df_irr[2016]['ggzz'].ZZMass >= opt.LOWER_BOUND) & (df_irr[2016]['ggzz'].ZZMass <= opt.UPPER_BOUND) & (df_irr[2016]['ggzz'][var] >= bin_low) & (df_irr[2016]['ggzz'][var] < bin_high)].copy() + df_2017_ggzz = df_irr[2017]['ggzz'][(df_irr[2017]['ggzz'].ZZMass >= opt.LOWER_BOUND) & (df_irr[2017]['ggzz'].ZZMass <= opt.UPPER_BOUND) & (df_irr[2017]['ggzz'][var] >= bin_low) & (df_irr[2017]['ggzz'][var] < bin_high)].copy() + df_2018_ggzz = df_irr[2018]['ggzz'][(df_irr[2018]['ggzz'].ZZMass >= opt.LOWER_BOUND) & (df_irr[2018]['ggzz'].ZZMass <= opt.UPPER_BOUND) & (df_irr[2018]['ggzz'][var] >= bin_low) & (df_irr[2018]['ggzz'][var] < bin_high)].copy() + df = pd.concat([df_2016_qqzz.drop(columns=['KFactor_EW_qqZZ','KFactor_QCD_qqZZ_M']),df_2017_qqzz.drop(columns=['KFactor_EW_qqZZ','KFactor_QCD_qqZZ_M']), + df_2018_qqzz.drop(columns=['KFactor_EW_qqZZ','KFactor_QCD_qqZZ_M']),df_2016_ggzz.drop(columns=['KFactor_QCD_ggZZ_Nominal']), + df_2017_ggzz.drop(columns=['KFactor_QCD_ggZZ_Nominal']),df_2018_ggzz.drop(columns=['KFactor_QCD_ggZZ_Nominal'])]) + # In case of zzfloating len_tot is overwritten (previous definition at the beginning of for loops) + len_tot = df['weight'].sum() # Total number of bkg b events in all final states and across years + yield_bkg['ZZ_'+str(i)] = len_tot + df = df_irr[year][bkg][sel].copy() len_bin = df['weight'].sum() # Number of bkg events in bin i if(len_tot <= 0): @@ -387,8 +403,10 @@ def doTemplates(df_irr, df_red, binning, var, var_string, var_2nd='None'): w = np.asarray(w).astype('float') # ------ - if((obs_name == 'rapidity4l') | acFlag): + if((obs_name == 'rapidity4l') | ('cos' in obs_name) | ('phi' in obs_name) | ('eta' in obs_name) | acFlag): histo = ROOT.TH1D("m4l_"+var_string+"_"+str(bin_low)+"_"+str(bin_high), "m4l_"+var_string+"_"+str(bin_low)+"_"+str(bin_high), 20, opt.LOWER_BOUND, opt.UPPER_BOUND) + elif doubleDiff and 'rapidity' in var_string: + histo = ROOT.TH1D("m4l_"+var_string+"_"+str(bin_low)+"_"+str(bin_high)+"_"+str(bin_low_2nd)+"_"+str(bin_high_2nd), "m4l_"+var_string+"_"+str(bin_low)+"_"+str(bin_high)+str(bin_low_2nd)+"_"+str(bin_high_2nd), 20, opt.LOWER_BOUND, opt.UPPER_BOUND) elif doubleDiff: histo = ROOT.TH1D("m4l_"+var_string+"_"+str(int(bin_low))+"_"+str(int(bin_high))+"_"+str(int(bin_low_2nd))+"_"+str(int(bin_high_2nd)), "m4l_"+var_string+"_"+str(int(bin_low))+"_"+str(int(bin_high))+str(int(bin_low_2nd))+"_"+str(int(bin_high_2nd)), 20, opt.LOWER_BOUND, opt.UPPER_BOUND) else: @@ -398,8 +416,10 @@ def doTemplates(df_irr, df_red, binning, var, var_string, var_2nd='None'): histo.FillN(len(mass4l), mass4l, w) smoothAndNormaliseTemplate(histo, 1) - if ((obs_name == 'rapidity4l') | ('cos' in obs_name) | ('phi' in obs_name) | acFlag): + if ((obs_name == 'rapidity4l') | ('cos' in obs_name) | ('phi' in obs_name) | ('eta' in obs_name) | acFlag): outFile = ROOT.TFile.Open(str(year)+"/"+var_string+"/XSBackground_"+bkg+"_"+f+"_"+var_string+"_"+str(bin_low)+"_"+str(bin_high)+".root", "RECREATE") + elif doubleDiff and 'rapidity' in var_string: + outFile = ROOT.TFile.Open(str(year)+"/"+var_string+"/XSBackground_"+bkg+"_"+f+"_"+var_string+"_"+str(bin_low)+"_"+str(bin_high)+"_"+str(bin_low_2nd)+"_"+str(bin_high_2nd)+".root", "RECREATE") elif doubleDiff: outFile = ROOT.TFile.Open(str(year)+"/"+var_string+"/XSBackground_"+bkg+"_"+f+"_"+var_string+"_"+str(int(bin_low))+"_"+str(int(bin_high))+"_"+str(int(bin_low_2nd))+"_"+str(int(bin_high_2nd))+".root", "RECREATE") else: @@ -417,7 +437,6 @@ def doTemplates(df_irr, df_red, binning, var, var_string, var_2nd='None'): sel_f_state_zx = df_red[year]['FinState'] == 1 elif(f == '2e2mu'): sel_f_state_zx = (df_red[year]['FinState'] == 2) | (df_red[year]['FinState'] == 3) - #df = df_red[year][(sel_f_state_zx) & (df_red[year].Z2Mass < 60) & (df_red[year].ZZMass >= 105) & (df_red[year].ZZMass <=160)].copy() df = df_red[year][(sel_f_state_zx) & (df_red[year].ZZMass >= opt.LOWER_BOUND) & (df_red[year].ZZMass <=opt.UPPER_BOUND)].copy() df_inclusive = df.copy() len_tot = df['yield_SR'].sum() # Total number of bkg events in final state f @@ -454,16 +473,20 @@ def doTemplates(df_irr, df_red, binning, var, var_string, var_2nd='None'): w = df['yield_SR'].to_numpy() w = np.asarray(w).astype('float') # ------ - if((obs_name == 'rapidity4l') | ('cos' in obs_name) | ('phi' in obs_name) | acFlag): + if((obs_name == 'rapidity4l') | ('cos' in obs_name) | ('phi' in obs_name) | ('eta' in obs_name) | acFlag): histo = ROOT.TH1D("m4l_"+var_string+"_"+str(bin_low)+"_"+str(bin_high), "m4l_"+var_string+"_"+str(bin_low)+"_"+str(bin_high), 20, opt.LOWER_BOUND, opt.UPPER_BOUND) + elif doubleDiff and 'rapidity' in var_string: + histo = ROOT.TH1D("m4l_"+var_string+"_"+str(bin_low)+"_"+str(bin_high)+"_"+str(bin_low_2nd)+"_"+str(bin_high_2nd), "m4l_"+var_string+"_"+str(bin_low)+"_"+str(bin_high)+str(bin_low_2nd)+"_"+str(bin_high_2nd), 20, opt.LOWER_BOUND, opt.UPPER_BOUND) elif doubleDiff: histo = ROOT.TH1D("m4l_"+var_string+"_"+str(int(bin_low))+"_"+str(int(bin_high))+"_"+str(int(bin_low_2nd))+"_"+str(int(bin_high_2nd)), "m4l_"+var_string+"_"+str(int(bin_low))+"_"+str(int(bin_high))+str(int(bin_low_2nd))+"_"+str(int(bin_high_2nd)), 20, opt.LOWER_BOUND, opt.UPPER_BOUND) else: histo = ROOT.TH1D("m4l_"+var_string+"_"+str(int(bin_low))+"_"+str(int(bin_high)), "m4l_"+var_string+"_"+str(int(bin_low))+"_"+str(int(bin_high)), 20, opt.LOWER_BOUND, opt.UPPER_BOUND) histo.FillN(len(mass4l), mass4l, w) smoothAndNormaliseTemplate(histo, 1) - if((obs_name == 'rapidity4l') | ('cos' in obs_name) | ('phi' in obs_name) | acFlag): + if((obs_name == 'rapidity4l') | ('cos' in obs_name) | ('phi' in obs_name) | ('eta' in obs_name) | acFlag): outFile = ROOT.TFile.Open(str(year)+"/"+var_string+"/XSBackground_ZJetsCR_"+f+"_"+var_string+"_"+str(bin_low)+"_"+str(bin_high)+".root", "RECREATE") + elif doubleDiff and 'rapidity' in var_string: + outFile = ROOT.TFile.Open(str(year)+"/"+var_string+"/XSBackground_ZJetsCR_"+f+"_"+var_string+"_"+str(bin_low)+"_"+str(bin_high)+"_"+str(bin_low_2nd)+"_"+str(bin_high_2nd)+".root", "RECREATE") elif doubleDiff: outFile = ROOT.TFile.Open(str(year)+"/"+var_string+"/XSBackground_ZJetsCR_"+f+"_"+var_string+"_"+str(int(bin_low))+"_"+str(int(bin_high))+"_"+str(int(bin_low_2nd))+"_"+str(int(bin_high_2nd))+".root", "RECREATE") else: @@ -483,8 +506,8 @@ def doTemplates(df_irr, df_red, binning, var, var_string, var_2nd='None'): # General settings bkgs = ['ZZTo4lext', 'ggTo2e2mu_Contin_MCFM701', 'ggTo2e2tau_Contin_MCFM701', 'ggTo2mu2tau_Contin_MCFM701', 'ggTo4e_Contin_MCFM701', 'ggTo4mu_Contin_MCFM701', 'ggTo4tau_Contin_MCFM701'] -eos_path_FR = '/eos/cms/store/group/phys_higgs/cmshzz4l/cjlst/RunIILegacy/200205_CutBased/' -eos_path = '/eos/user/a/atarabin/' +eos_path_FR = path['eos_path_FR'] +eos_path = path['eos_path'] key = 'candTree' # years = [2016, 2017, 2018] @@ -493,77 +516,79 @@ def doTemplates(df_irr, df_red, binning, var, var_string, var_2nd='None'): if (opt.YEAR == '2018'): years = [2018] if (opt.YEAR == 'Full'): years = [2016,2017,2018] -if not 'vs' in opt.OBSBINS: #It is not a double-differential analysis - obs_bins = {0:(opt.OBSBINS.split("|")[1:(len(opt.OBSBINS.split("|"))-1)]),1:['0','inf']}[opt.OBSBINS=='inclusive'] - obs_bins = [float(i) for i in obs_bins] #Convert a list of str to a list of float - doubleDiff = False - print 'It is a single-differential measurement, binning', obs_bins -else: #It is a double-differential analysis - doubleDiff = True - # The structure of obs_bins is: - # index of the dictionary is the number of the bin - # [obs_bins_low, obs_bins_high, obs_bins_low_2nd, obs_bins_high_2nd] - # The first two entries are the lower and upper bound of the first variable - # The second two entries are the lower and upper bound of the second variable - if opt.OBSBINS.count('vs')==1 and opt.OBSBINS.count('/')>=1: #Situation like this one '|0|1|2|3|20| vs |0|10|20|45|90|250| / |0|10|20|80|250| / |0|20|90|250| / |0|25|250|' - obs_bins_tmp = opt.OBSBINS.split(" vs ") #['|0|1|2|3|20|', '|0|10|20|45|90|250| / |0|10|20|80|250| / |0|20|90|250| / |0|25|250|'] - obs_bins_1st = obs_bins_tmp[0].split('|')[1:len(obs_bins_tmp[0].split('|'))-1] #['0', '1', '2', '3', '20'] - obs_bins_1st = [float(i) for i in obs_bins_1st] #Convert a list of str to a list of float - obs_bins_tmp = obs_bins_tmp[1].split(' / ') #['|0|10|20|45|90|250|', '|0|10|20|80|250|', '|0|20|90|250|', '|0|25|250|'] - obs_bins_2nd = {} - for i in range(len(obs_bins_tmp)): #At the end of the loop -> obs_bins_2nd {0: ['0', '10', '20', '45', '90', '250'], 1: ['0', '10', '20', '80', '250'], 2: ['0', '20', '90', '250'], 3: ['0', '25', '250']} - obs_bins_2nd[i] = obs_bins_tmp[i].split('|')[1:len(obs_bins_tmp[i].split('|'))-1] - obs_bins_2nd[i] = [float(j) for j in obs_bins_2nd[i]] #Convert a list of str to a list of float - obs_bins = {} - k = 0 #Bin index - for i in range(len(obs_bins_1st)-1): - for j in range(len(obs_bins_2nd[i])-1): - obs_bins[k] = [] - obs_bins[k].append(obs_bins_1st[i]) - obs_bins[k].append(obs_bins_1st[i+1]) - obs_bins[k].append(obs_bins_2nd[i][j]) - obs_bins[k].append(obs_bins_2nd[i][j+1]) - k +=1 - elif opt.OBSBINS.count('vs')>1 and opt.OBSBINS.count('/')>1: #Situation like this one '|50|80| vs |10|30| / |50|80| vs |30|60| / |80|110| vs |10|25| / |80|110| vs |25|30|' - obs_bins_tmp = opt.OBSBINS.split(' / ') #['|50|80| vs |10|30|', '|50|80| vs |30|60|', '|80|110| vs |10|25|', '|80|110| vs |25|30|'] - obs_bins_1st={} - obs_bins_2nd={} - obs_bins={} - for i in range(len(obs_bins_tmp)): #At the end of the loop -> obs_bins_1st {0: ['50', '80'], 1: ['50', '80'], 2: ['80', '110'], 3: ['80', '110']} and obs_bins_2nd {0: ['10', '30'], 1: ['30', '60'], 2: ['10', '25'], 3: ['25', '30']} - obs_bins_tmp_bis = obs_bins_tmp[i].split(' vs ') - obs_bins_1st[i] = obs_bins_tmp_bis[0].split('|')[1:len(obs_bins_tmp_bis[0].split('|'))-1] - obs_bins_1st[i] = [float(j) for j in obs_bins_1st[i]] #Convert a list of str to a list of float - obs_bins_2nd[i] = obs_bins_tmp_bis[1].split('|')[1:len(obs_bins_tmp_bis[1].split('|'))-1] - obs_bins_2nd[i] = [float(j) for j in obs_bins_2nd[i]] #Convert a list of str to a list of float - obs_bins[i] = [] - obs_bins[i].append(obs_bins_1st[i][0]) - obs_bins[i].append(obs_bins_1st[i][1]) - obs_bins[i].append(obs_bins_2nd[i][0]) - obs_bins[i].append(obs_bins_2nd[i][1]) - elif opt.OBSBINS.count('vs')==1 and opt.OBSBINS.count('/')==0: #Situation like this one '|0|1|2|3|20| vs |0|10|20|45|90|250|' - obs_bins_tmp = opt.OBSBINS.split(" vs ") #['|0|1|2|3|20|', '|0|10|20|45|90|250|'] - obs_bins_1st = obs_bins_tmp[0].split('|')[1:len(obs_bins_tmp[0].split('|'))-1] #['0', '1', '2', '3', '20'] - obs_bins_1st = [float(i) for i in obs_bins_1st] #Convert a list of str to a list of float - obs_bins_2nd = obs_bins_tmp[1].split('|')[1:len(obs_bins_tmp[1].split('|'))-1] #['0', '10', '20', '45', '90', '250'] - obs_bins_2nd = [float(i) for i in obs_bins_2nd] #Convert a list of str to a list of float - obs_bins = {} - k = 0 #Bin index - for i in range(len(obs_bins_1st)-1): - for j in range(len(obs_bins_2nd)-1): - obs_bins[k] = [] - obs_bins[k].append(obs_bins_1st[i]) - obs_bins[k].append(obs_bins_1st[i+1]) - obs_bins[k].append(obs_bins_2nd[j]) - obs_bins[k].append(obs_bins_2nd[j+1]) - k +=1 - else: - print 'Problem in the definition of the binning' - quit() - print 'It is a double-differential measurement, binning for the 1st variable', obs_bins_1st, 'and for the 2nd variable', obs_bins_2nd - print obs_bins +obs_bins, doubleDiff = binning(opt.OBSNAME) + +# if not 'vs' in opt.OBSBINS: #It is not a double-differential analysis +# obs_bins = {0:(opt.OBSBINS.split("|")[1:(len(opt.OBSBINS.split("|"))-1)]),1:['0','inf']}[opt.OBSBINS=='inclusive'] +# obs_bins = [float(i) for i in obs_bins] #Convert a list of str to a list of float +# doubleDiff = False +# print 'It is a single-differential measurement, binning', obs_bins +# else: #It is a double-differential analysis +# doubleDiff = True +# # The structure of obs_bins is: +# # index of the dictionary is the number of the bin +# # [obs_bins_low, obs_bins_high, obs_bins_low_2nd, obs_bins_high_2nd] +# # The first two entries are the lower and upper bound of the first variable +# # The second two entries are the lower and upper bound of the second variable +# if opt.OBSBINS.count('vs')==1 and opt.OBSBINS.count('/')>=1: #Situation like this one '|0|1|2|3|20| vs |0|10|20|45|90|250| / |0|10|20|80|250| / |0|20|90|250| / |0|25|250|' +# obs_bins_tmp = opt.OBSBINS.split(" vs ") #['|0|1|2|3|20|', '|0|10|20|45|90|250| / |0|10|20|80|250| / |0|20|90|250| / |0|25|250|'] +# obs_bins_1st = obs_bins_tmp[0].split('|')[1:len(obs_bins_tmp[0].split('|'))-1] #['0', '1', '2', '3', '20'] +# obs_bins_1st = [float(i) for i in obs_bins_1st] #Convert a list of str to a list of float +# obs_bins_tmp = obs_bins_tmp[1].split(' / ') #['|0|10|20|45|90|250|', '|0|10|20|80|250|', '|0|20|90|250|', '|0|25|250|'] +# obs_bins_2nd = {} +# for i in range(len(obs_bins_tmp)): #At the end of the loop -> obs_bins_2nd {0: ['0', '10', '20', '45', '90', '250'], 1: ['0', '10', '20', '80', '250'], 2: ['0', '20', '90', '250'], 3: ['0', '25', '250']} +# obs_bins_2nd[i] = obs_bins_tmp[i].split('|')[1:len(obs_bins_tmp[i].split('|'))-1] +# obs_bins_2nd[i] = [float(j) for j in obs_bins_2nd[i]] #Convert a list of str to a list of float +# obs_bins = {} +# k = 0 #Bin index +# for i in range(len(obs_bins_1st)-1): +# for j in range(len(obs_bins_2nd[i])-1): +# obs_bins[k] = [] +# obs_bins[k].append(obs_bins_1st[i]) +# obs_bins[k].append(obs_bins_1st[i+1]) +# obs_bins[k].append(obs_bins_2nd[i][j]) +# obs_bins[k].append(obs_bins_2nd[i][j+1]) +# k +=1 +# elif opt.OBSBINS.count('vs')>1 and opt.OBSBINS.count('/')>1: #Situation like this one '|50|80| vs |10|30| / |50|80| vs |30|60| / |80|110| vs |10|25| / |80|110| vs |25|30|' +# obs_bins_tmp = opt.OBSBINS.split(' / ') #['|50|80| vs |10|30|', '|50|80| vs |30|60|', '|80|110| vs |10|25|', '|80|110| vs |25|30|'] +# obs_bins_1st={} +# obs_bins_2nd={} +# obs_bins={} +# for i in range(len(obs_bins_tmp)): #At the end of the loop -> obs_bins_1st {0: ['50', '80'], 1: ['50', '80'], 2: ['80', '110'], 3: ['80', '110']} and obs_bins_2nd {0: ['10', '30'], 1: ['30', '60'], 2: ['10', '25'], 3: ['25', '30']} +# obs_bins_tmp_bis = obs_bins_tmp[i].split(' vs ') +# obs_bins_1st[i] = obs_bins_tmp_bis[0].split('|')[1:len(obs_bins_tmp_bis[0].split('|'))-1] +# obs_bins_1st[i] = [float(j) for j in obs_bins_1st[i]] #Convert a list of str to a list of float +# obs_bins_2nd[i] = obs_bins_tmp_bis[1].split('|')[1:len(obs_bins_tmp_bis[1].split('|'))-1] +# obs_bins_2nd[i] = [float(j) for j in obs_bins_2nd[i]] #Convert a list of str to a list of float +# obs_bins[i] = [] +# obs_bins[i].append(obs_bins_1st[i][0]) +# obs_bins[i].append(obs_bins_1st[i][1]) +# obs_bins[i].append(obs_bins_2nd[i][0]) +# obs_bins[i].append(obs_bins_2nd[i][1]) +# elif opt.OBSBINS.count('vs')==1 and opt.OBSBINS.count('/')==0: #Situation like this one '|0|1|2|3|20| vs |0|10|20|45|90|250|' +# obs_bins_tmp = opt.OBSBINS.split(" vs ") #['|0|1|2|3|20|', '|0|10|20|45|90|250|'] +# obs_bins_1st = obs_bins_tmp[0].split('|')[1:len(obs_bins_tmp[0].split('|'))-1] #['0', '1', '2', '3', '20'] +# obs_bins_1st = [float(i) for i in obs_bins_1st] #Convert a list of str to a list of float +# obs_bins_2nd = obs_bins_tmp[1].split('|')[1:len(obs_bins_tmp[1].split('|'))-1] #['0', '10', '20', '45', '90', '250'] +# obs_bins_2nd = [float(i) for i in obs_bins_2nd] #Convert a list of str to a list of float +# obs_bins = {} +# k = 0 #Bin index +# for i in range(len(obs_bins_1st)-1): +# for j in range(len(obs_bins_2nd)-1): +# obs_bins[k] = [] +# obs_bins[k].append(obs_bins_1st[i]) +# obs_bins[k].append(obs_bins_1st[i+1]) +# obs_bins[k].append(obs_bins_2nd[j]) +# obs_bins[k].append(obs_bins_2nd[j+1]) +# k +=1 +# else: +# print 'Problem in the definition of the binning' +# quit() +# print 'It is a double-differential measurement, binning for the 1st variable', obs_bins_1st, 'and for the 2nd variable', obs_bins_2nd +# print obs_bins obs_name = opt.OBSNAME -if obs_name == 'D0m' or obs_name == 'D0hp' or obs_name == 'Dcp' or obs_name == 'Dint' or obs_name == 'DL1': acFlag = True +if obs_name == 'D0m' or obs_name == 'D0hp' or obs_name == 'Dcp' or obs_name == 'Dint' or obs_name == 'DL1' or obs_name == 'DL1Zg': acFlag = True else: acFlag = False print acFlag @@ -595,7 +620,7 @@ def doTemplates(df_irr, df_red, binning, var, var_string, var_2nd='None'): branches_ZX = ['ZZMass', 'Z1Flav', 'Z2Flav', 'LepLepId', 'LepEta', 'LepPt', 'Z1Mass', 'Z2Mass', 'ZZPt', 'ZZEta', 'JetPt', 'JetEta', 'costhetastar', 'helcosthetaZ1','helcosthetaZ2','helphi','phistarZ1', 'pTHj', 'TCjmax', 'TBjmax', 'mjj', 'pTj1', 'pTj2', 'mHj', 'mHjj', 'pTHjj', 'njets_pt30_eta4p7', - 'Dcp', 'D0m', 'D0hp', 'Dint', 'DL1', 'DL1int', 'DL1Zg', 'DL1Zgint'] + 'Dcp', 'D0m', 'D0hp', 'Dint', 'DL1', 'DL1int', 'DL1Zg', 'DL1Zgint','absdetajj'] dfZX={} for year in years: g_FR_mu_EB, g_FR_mu_EE, g_FR_e_EB, g_FR_e_EE = openFR(year) diff --git a/templates/plot_templates.cpp b/templates/plot_templates.cpp index f6dd630..c627d37 100644 --- a/templates/plot_templates.cpp +++ b/templates/plot_templates.cpp @@ -118,6 +118,30 @@ int main (int argc, char ** argv){ TCanvas *c1; setCavasAndStyles("c1",c1,""); + TString obsTag = argv[1]; + const int N_BINS = argc-3; + TString binRange[N_BINS] = {}; + TString binRangeLow[N_BINS] = {}; + TString binRangeHigh[N_BINS] = {}; + TString binRangeLeg[N_BINS] = {}; + for (int i=0; i