Skip to content

Commit

Permalink
pipeline to run entire workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
bonanomi committed Dec 9, 2020
1 parent 309f640 commit 180add6
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 13 deletions.
5 changes: 5 additions & 0 deletions LHScans/plot_LLScan.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ def BuildScan(scan, param, files, color, yvals, ycut):
if(obsName == 'njets_pt30_eta2p5'): label = 'nJets, pT>30 GeV, |#eta|<2.5'
if(obsName == 'pTj1'): label = 'p_{T}^{(Lead. jet)} (GeV)'
if(obsName == 'mass4l'): label = 'm_{4\ell} (GeV)'
if(obsName == 'costhetastar'): label = 'cos(#theta^{*})'
if(obsName == 'costhetaZ1'): label = 'cos(#theta_{1})'
if(obsName == 'costhetaZ2'): label = 'cos(#theta_{2})'
if(obsName == 'phistar'): label = '#Phi^{#star}'
if(obsName == 'phi'): label = '#Phi'
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
nBins = len(obs_bins)
Expand Down
2 changes: 1 addition & 1 deletion coefficients/RunCoefficients.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def createDataframe(d_sig,fail,gen,xsec,signal,lumi):
'GENZ_DaughtersId', 'GENZ_MomId', 'passedFiducialSelection_bbf',
'PUWeight', 'genHEPMCweight','GENnjets_pt30_eta2p5',
'GenCleanedJetPt', 'GenCleanedJetEta', 'GENpTj1',
'GENmassZ2', 'GENmassZ1', 'GENcosThetaStar',
'GENmassZ2', 'GENmassZ1',
'GENcosTheta1','GENcosTheta2','GENcosThetaStar','GENPhi','GENPhi1']
if signal == 'ggH125': b_sig.append('ggH_NNLOPS_weight') #Additional entry for the weight in case of ggH
if not fail: b_sig.extend(['ZZMass', 'ZZPt', 'ZZy', 'Z1Mass', 'Z2Mass', 'ZZEta', 'Z1Flav', 'Z2Flav',
Expand Down
7 changes: 6 additions & 1 deletion fit/createXSworkspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,13 @@ def createXSworkspace(obsName, channel, nBins, obsBin, observableBins, usecfacto
# mass4mu = ROOT.RooRealVar("mass4mu", "mass4mu", 105.0, 140.0)
# mass2e2mu = ROOT.RooRealVar("mass2e2mu", "mass2e2mu",105.0, 140.0)
if (not obsName=="mass4l"):
if (obsName=="rapidity4l" or obsName=="cosThetaStar" or obsName=="cosTheta1" or obsName=="cosTheta2" or obsName=="Phi" or obsName=="Phi1"):
if (obsName=="rapidity4l" or obsName=="costhetastar" or obsName=="costhetaZ1" or obsName=="costhetaZ2" or obsName=="phi" or obsName=="phistar"):
if(obsName == "rapidity4l") : obsName_help = "ZZy"
elif(obsName == "costhetaZ1") : obsName_help = "helcosthetaZ1"
elif(obsName == "costhetaZ2") : obsName_help = "helcosthetaZ2"
elif(obsName == "phi") : obsName_help = "helphi"
elif(obsName == "phistar") : obsName_help = "phistarZ1"
elif(obsName == "costhetastar") : obsName_help = "costhetastar"
observable = ROOT.RooRealVar(obsName_help,obsName_help,float(obs_bin_lowest),float(obs_bin_highest))
# observable = ROOT.RooRealVar(obsName,obsName,-1.0*float(obs_bin_highest),float(obs_bin_highest))
else:
Expand Down
115 changes: 115 additions & 0 deletions pipeline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import numpy as np
import pandas as pd
import uproot
import math
import ROOT
import ROOT
import sys, os, pwd, commands
from subprocess import *
import optparse, shlex, re
import time
from decimal import *
import json

def parseOptions():

global opt, args, runAllSteps

usage = ('usage: %prog [options]\n'
+ '%prog -h for help')
parser = optparse.OptionParser(usage)

# input options
parser.add_option('', '--obsName', dest='OBSNAME', type='string',default='', help='Name of the observable, supported: "inclusive", "pT4l", "eta4l", "massZ2", "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('', '--year', dest='YEAR', type='string',default='', help='Year -> 2016 or 2017 or 2018 or Full')
parser.add_option('', '--unblind', action='store_true', dest='UNBLIND', default=False, help='Use real data')
parser.add_option('', '--fitOnly', action='store_true', dest='FITONLY', default=False, help='Run only fit')
# store options and arguments as global variables
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()


# parse the arguments and options
global opt, args, runAllSteps
parseOptions()

# Define function for processing of os command
def processCmd(cmd, quiet = 0):
output = '\n'
p = Popen(cmd, shell=True, stdout=PIPE, stderr=STDOUT, bufsize=-1)
for line in iter(p.stdout.readline, ''):
output=output+str(line)
print line,
p.stdout.close()
if p.wait() != 0:
raise RuntimeError("%r failed, exit status: %d" % (cmd, p.returncode))
return output

def pipeline():
# 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']
## Run for the given observable
obsName = str(opt.OBSNAME)
obsBins = str(opt.OBSBINS)
year = str(opt.YEAR)
unblind = opt.UNBLIND
fitOnly = opt.FITONLY

print('============================================================')
print('============================================================')
print('=== RUNNING THE WORKFLOW FOR THE FOLLOWING CONFIGURATION ===')
print('=== %s %s %s %r ===' %(obsName, year, obsBins, unblind))
print('============================================================')
print('============================================================')

if not fitOnly:
os.chdir('./coefficients')

cmd = 'python RunCoefficients.py --obsName "'+obsName+'" --obsBins "'+obsBins+'" --year "'+year+'"'
print cmd
output = processCmd(cmd)
print output

cmd = 'python pdfUncertainty.py --obsName "'+obsName+'" --obsBins "'+obsBins+'" --year "'+year+'"'
output = processCmd(cmd)
print output

os.chdir('../templates')

cmd = 'python RunTemplates.py --obsName "'+obsName+'" --obsBins "'+obsBins+'" --year "'+year+'"'
output = processCmd(cmd)
print output

os.chdir('../fit')

if fitOnly: os.chdir('./fit')
cmd = 'python RunFiducialXS.py --obsName "'+obsName+'" --obsBins "'+obsBins+'" --year "'+year+'"'
output = processCmd(cmd)
print output

if unblind:
cmd += ' --unblind True'
output = processCmd(cmd)
print output

os.chdir('../LHScans')

cmd = 'python plot_LLScan.py --obsName "'+obsName+'" --obsBins "'+obsBins+'" --year "'+year+'"'
output = processCmd(cmd)
print output

if unblind:
cmd += ' --unblind True'
output = processCmd(cmd)
print output

pipeline()

12 changes: 6 additions & 6 deletions producePlots.py
Original file line number Diff line number Diff line change
Expand Up @@ -1168,19 +1168,19 @@ def plotXS(obsName, obs_bins):
elif (obsName=="rapidity4l"):
label = "|y(H)|"
unit = ""
elif (obsName=="cosThetaStar"):
elif (obsName=="costhetastar"):
label = "|cos#theta*|"
unit = ""
elif (obsName=="cosTheta1"):
elif (obsName=="costhetaZ1"):
label = "|cos#theta_{1}|"
unit = ""
elif (obsName=="cosTheta2"):
elif (obsName=="costhetaZ2"):
label = "|cos#theta_{2}|"
unit = ""
elif (obsName=="Phi"):
elif (obsName=="phi"):
label = "|#Phi|"
unit = ""
elif (obsName=="Phi1"):
elif (obsName=="phistar"):
label = "|#Phi_{1}|"
unit = ""
elif (obsName=="mass4l"):
Expand All @@ -1189,7 +1189,7 @@ def plotXS(obsName, obs_bins):
else:
label = obsName
unit = ""

print label
c = TCanvas("c",obsName, 1400, 1400)
if(opt.SETLOG): c.SetLogy()
if (not obsName=="mass4l"): c.SetBottomMargin(0.35)
Expand Down
9 changes: 5 additions & 4 deletions templates/RunTemplates.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,14 +351,14 @@ def doTemplates(df_irr, df_red, binning, var, var_string):
w = df['weight'].to_numpy()
w = np.asarray(w).astype('float')
# ------
if(obs_name == 'rapidity4l'):
if((obs_name == 'rapidity4l') | ('cos' in obs_name) | ('phi' in obs_name)):
histo = ROOT.TH1D("m4l_"+var_string+"_"+str(bin_low)+"_"+str(bin_high), "m4l_"+var_string+"_"+str(bin_low)+"_"+str(bin_high), 20, 105, 140)
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, 105, 140)
print (histo.GetName())
histo.FillN(len(mass4l), mass4l, w)
smoothAndNormaliseTemplate(histo, 1)
if (obs_name == 'rapidity4l'):
if((obs_name == 'rapidity4l') | ('cos' in obs_name) | ('phi' in obs_name)):
outFile = ROOT.TFile.Open(str(year)+"/"+var_string+"/XSBackground_"+bkg+"_"+f+"_"+var_string+"_"+str(bin_low)+"_"+str(bin_high)+".root", "RECREATE")
else:
outFile = ROOT.TFile.Open(str(year)+"/"+var_string+"/XSBackground_"+bkg+"_"+f+"_"+var_string+"_"+str(int(bin_low))+"_"+str(int(bin_high))+".root", "RECREATE")
Expand Down Expand Up @@ -395,13 +395,14 @@ def doTemplates(df_irr, df_red, binning, var, var_string):
w = df['yield_SR'].to_numpy()
w = np.asarray(w).astype('float')
# ------
if(obs_name == 'rapidity4l'):
if((obs_name == 'rapidity4l') | ('cos' in obs_name) | ('phi' in obs_name)):

histo = ROOT.TH1D("m4l_"+var_string+"_"+str(bin_low)+"_"+str(bin_high), "m4l_"+var_string+"_"+str(bin_low)+"_"+str(bin_high), 20, 105, 140)
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, 105, 140)
histo.FillN(len(mass4l), mass4l, w)
smoothAndNormaliseTemplate(histo, 1)
if(obs_name == 'rapidity4l'):
if((obs_name == 'rapidity4l') | ('cos' in obs_name) | ('phi' in obs_name)):
outFile = ROOT.TFile.Open(str(year)+"/"+var_string+"/XSBackground_ZJetsCR_"+f+"_"+var_string+"_"+str(bin_low)+"_"+str(bin_high)+".root", "RECREATE")
else:
outFile = ROOT.TFile.Open(str(year)+"/"+var_string+"/XSBackground_ZJetsCR_"+f+"_"+var_string+"_"+str(int(bin_low))+"_"+str(int(bin_high))+".root", "RECREATE")
Expand Down
10 changes: 9 additions & 1 deletion templates/plot_templates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,20 @@ int main (int argc, char ** argv){
// TString binRangeHigh[N_BINS] = {"1", "2", "3", "4", "20"};
// TString binRangeLeg[N_BINS] = {"nJet=0", "nJet=1", "nJet=2", "nJet=3", "nJet>=4"};

TString obsTag = "pTj1";
/*TString obsTag = "pTj1";
const int N_BINS = 4;
TString binRange[N_BINS] = {"30_55", "55_95", "95_200", "200_13000"};
TString binRangeLow[N_BINS] = {"30", "55", "95", "200"};
TString binRangeHigh[N_BINS] = {"55", "95", "200", "13000"};
TString binRangeLeg[N_BINS] = {"30 < pTj1 < 55 GeV", "55 < pTj1 < 95 GeV", "95 < pTj1 < 200 GeV", "200 < pTj1 < 1300 GeV"};
*/

TString obsTag = "costhetastar";
const int N_BINS = 5;
TString binRange[N_BINS] = {"0.0_0.2", "0.2_0.4", "0.4_0.6", "0.6_0.8", "0.8_1.0"};
TString binRangeLow[N_BINS] = {"0.0", "0.2", "0.4", "0.6", "0.8"};
TString binRangeHigh[N_BINS] = {"0.2", "0.4", "0.6", "0.8", "1.0"};
TString binRangeLeg[N_BINS] = {"0.0 < cos(#theta) < 0.2 ", "55 < cos(#theta) < 0.4 ", "0.4 < cos(#theta) < 0.6 ", "0.6 < cos(#theta) < 0.8 ", "0.8 < cos(#theta) < 1.0 "};

const int N_BKGS = 3;
TString bkgName[N_BKGS] = {"qqzz", "ggzz", "ZJetsCR"};
Expand Down

0 comments on commit 180add6

Please sign in to comment.