def _setConfiguration(self, trigger, usetag): self.baseDir = common.getBaseDirectory() # config nbjet and selections if trigger == "mu": self.selections = ["emu", "mumu", "mutau", "mu4j"] elif trigger == "e": self.selections = ["ee", "emu2", "etau", "e4j"] if usetag == "1b": self.nbjet = "==1" if usetag == "2b": self.nbjet = ">1" # read nGen from file dfNGen = pd.read_pickle(self.baseDir + "data/pickles/ngen.pkl") self.dfNGen = dfNGen self.ttxs, self.txs = 832, 35.85 * 2 if self.variation == 'TTXSUp': self.ttxs = self.ttxs * 1.05 if self.variation == 'TWXSUp': self.txs = self.txs * 1.05 self.c_ttxs = self.ttxs / (self.ttxs + self.txs) self.c_txs = self.txs / (self.ttxs + self.txs) self.arrayToMatrix = np.array([[0, 2, 9, 10, 11, 15], [2, 1, 12, 13, 14, 16], [9, 12, 3, 5, 6, 17], [10, 13, 5, 4, 7, 18], [11, 14, 6, 7, 8, 19], [15, 16, 17, 18, 19, 20]])
def _setConfiguration(self): self.baseDir = common.getBaseDirectory() if self.selection == "mumu": if self.nbjet == '==1': self.workingPoint = 0.07 if self.nbjet == '>1': self.workingPoint = 0.07 if self.selection == "ee": if self.nbjet == '==1': self.workingPoint = 0.05 if self.nbjet == '>1': self.workingPoint = 0.2 # read nGen from file dfNGen = pd.read_pickle(self.baseDir + "data/pickles/ngen.pkl") self.dfNGen = dfNGen self.ttxs, self.txs = 832, 35.85 * 2 if self.variation == 'TTXSUp': self.ttxs = self.ttxs * 1.05 if self.variation == 'TWXSUp': self.txs = self.txs * 1.05 self.c_ttxs = self.ttxs / (self.ttxs + self.txs) self.c_txs = self.txs / (self.ttxs + self.txs) self.arrayToMatrix = np.array([[0, 2, 9, 10, 11, 15], [2, 1, 12, 13, 14, 16], [9, 12, 3, 5, 6, 17], [10, 13, 5, 4, 7, 18], [11, 14, 6, 7, 8, 19], [15, 16, 17, 18, 19, 20]])
def templateVariation(region, shaping): baseDir = common.getBaseDirectory() # config if shaping: folderType = 'shaping' else: folderType = 'counting' # nominal - dwon dx_list = [] for variation in ['EPt', 'MuPt', 'TauPt']: x0 = np.load(baseDir + "data/templates/{}_{}Region/X_{}.npy".format( folderType, region, '')) x1 = np.load(baseDir + "data/templates/{}_{}Region/X_{}Down.npy".format( folderType, region, variation)) dx = tc.from_numpy((x0 - x1)).type(tc.FloatTensor).to(device) dx_list.append(dx) # (up-down)/2 for variation in ['JES', 'JER', 'BTag', 'Mistag']: x1 = np.load(baseDir + "data/templates/{}_{}Region/X_{}Down.npy".format( folderType, region, variation)) x2 = np.load(baseDir + "data/templates/{}_{}Region/X_{}Up.npy".format( folderType, region, variation)) dx = tc.from_numpy((x2 - x1) / 2).type(tc.FloatTensor).to(device) dx_list.append(dx) return dx_list
def __init__(self): self.tb = BFSolver_Toolbox() self.baseDir = common.getBaseDirectory() counts = pd.read_pickle(self.baseDir + "data/counts/count_.pkl") self.a, self.aVar = counts.acc, counts.accVar self.ndata, self.ndataVar = counts.ndata, counts.ndataVar self.nmcbg, self.nmcbgVar = counts.nmcbg, counts.nmcbgVar self.nfake, self.nfakeVar = counts.nfake, counts.nfakeVar
def __init__(self, selection, nbjet): self.selection = selection self.nbjet = nbjet self.var_list = common.featureList() self.nvar = len(self.var_list) if nbjet == '==1': self.bname = '1b' if nbjet == '>1': self.bname = '2b' if self.selection[-1] == 'p': self.selection = self.selection[0:-1] self.norm = np.load(common.getBaseDirectory() + "data/networks/{}{}_norm.npy".format( self.selection, self.bname)).item() self.net = torch.load( common.getBaseDirectory() + "data/networks/{}{}.pt".format(self.selection, self.bname))
def __init__(self, inputRootFileName, selection): self.baseDir = common.getBaseDirectory() self.inputRootFile = root.TFile(self.baseDir + "data/root/" + inputRootFileName) self.selection = selection self.lumin = 35.864 self._getCrossection() self._getNameList()
def loadData(self): MCzz = DFCutter(self.selection, self.nbjet, "mcdiboson").getDataFrame() MCdy = DFCutter(self.selection, self.nbjet, "mcdy").getDataFrame() MCt = DFCutter(self.selection, self.nbjet, "mct").getDataFrame() MCtt = DFCutter(self.selection, self.nbjet, "mctt").getDataFrame() MCsg = pd.concat([MCt, MCtt], ignore_index=True) if self.selection == 'mumu': MCsg0 = MCsg.query('(genCategory != 14) & (genCategory != 5)') MCsg1 = MCsg.query('(genCategory == 14) | (genCategory == 5)') if self.selection == 'ee': MCsg0 = MCsg.query('(genCategory != 10) & (genCategory != 4)') MCsg1 = MCsg.query('(genCategory == 10) | (genCategory == 4)') MClist = [MCzz, MCdy, MCsg0, MCsg1] self.df_list, self.N_list, self.NRaw_list = [], [], [] for i in range(len(MClist)): #MClist[i] = MClist[i].reset_index(drop=True) n = int(np.sum(MClist[i].eventWeight)) nRaw = int(np.sum(MClist[i].eventWeight / MClist[i].eventWeightSF)) df = MClist[i].sample(int(n), replace=False) self.N_list.append(n) self.NRaw_list.append(nRaw) self.df_list.append(df) MCbkg = pd.concat(self.df_list[0:3], ignore_index=True) MCsig = self.df_list[3] drop_list = [v for v in MCsig.columns if not v in self.var_list] MCbkg.drop(drop_list, axis=1, inplace=True) MCsig.drop(drop_list, axis=1, inplace=True) MCbkg['label'] = 0 MCsig['label'] = 1 df_train = pd.concat([MCbkg, MCsig], ignore_index=True) df_train = df_train.reset_index(drop=True) self.norm = {} for v in df_train.columns: if v != 'label': mu = df_train[v].mean() sigma = df_train[v].std() df_train[v] = (df_train[v] - mu) / sigma self.norm[v] = (mu, sigma) np.save( common.getBaseDirectory() + "data/networks/{}{}_norm.npy".format(self.selection, self.bname), self.norm) self.df_train = df_train
def configTemplateVariation(self, region, shaping=False): baseDir = common.getBaseDirectory() if shaping: folderType = 'shaping' else: folderType = 'counting' # nominal - dwon dx_list = [] for variation in ['EPt', 'MuPt', 'TauPt']: x0 = np.load(baseDir + "data/templates/{}_{}Region/X_{}.npy".format( folderType, region, '')) x1 = np.load(baseDir + "data/templates/{}_{}Region/X_{}Down.npy".format( folderType, region, variation)) dx = (x0 - x1) dx_list.append(dx) self.dx_energye = dx_list[0] self.dx_energym = dx_list[1] self.dx_energyt = dx_list[2] # (up-down)/2 dx_list = [] for variation in ['JES', 'JER', 'BTag', 'Mistag']: x1 = np.load(baseDir + "data/templates/{}_{}Region/X_{}Down.npy".format( folderType, region, variation)) x2 = np.load(baseDir + "data/templates/{}_{}Region/X_{}Up.npy".format( folderType, region, variation)) dx = (x2 - x1) / 2 dx_list.append(dx) self.dx_jes = dx_list[0] self.dx_jer = dx_list[1] self.dx_btag = dx_list[2] self.dx_mistag = dx_list[3]
def __init__(self, selection, nbjet, name, njet=None, TightTau=False): ''' initialize a DFCutter with selection and name For Example, cutter = DFCutter("mumu","mctt") ''' self.selection = selection self.name = name self.baseDir = common.getBaseDirectory() folderOfSelection = self.selection if self.selection == "emu2": folderOfSelection = 'emu' if self.selection == "mutau_fakes": folderOfSelection = 'mutau' if self.selection == "etau_fakes": folderOfSelection = 'etau' if self.selection == 'mumuc': folderOfSelection = 'mumu' if self.selection == 'eec': folderOfSelection = 'ee' self.pickleDirectry = self.baseDir + "data/pickles/{}/".format( folderOfSelection) if TightTau: self.pickleDirectry = self.baseDir + "data/pickles_tightTau/{}/".format( folderOfSelection) # default jet requirments self.nb = " & (nBJets{})".format(nbjet) if njet is None: if '4j' in self.selection: self.nj = " & (nJets >= 4)" else: self.nj = " & (nJets >= 2)" else: self.nj = " & (nJets {})".format(njet)
def __init__(self,beta0, controlRegion=None): self.beta0 = beta0 # read sigma of beta0 baseDir = common.getBaseDirectory() sig = np.load(baseDir + 'data/combine/sigma.npy') var = np.load(baseDir + 'data/combine/covar.npy') self.sig_syst = sig[1:] self.var_stat = var[0] self.ivar_stat = np.linalg.pinv(self.var_stat) # some configuration self.n = var.shape[0]-1 self.param0 = np.r_[0.1081*np.ones(3), np.zeros(self.n)] # config control region self.controlRegion = controlRegion if not controlRegion is None: self.model1 = controlRegion[0] self.X1 = controlRegion[1] self.Y1 = controlRegion[2] self.lsEstimator()
def summaryCounts(): counts = {} cols = [ 'acc', 'accVar', 'nmcbg', 'nmcbgVar', 'nfake', 'nfakeVar', 'ndata', 'ndataVar' ] # nominal count df0 = pd.read_pickle(common.getBaseDirectory() + "data/counts/count_.pkl") count0 = [] for c in cols: count0.append(np.r_[df0[c][0], df0[c][1], df0[c][2], df0[c][3]]) counts['nominal'] = count0 # variate up for variation in ['TTXS', 'TWXS']: dfup = pd.read_pickle(common.getBaseDirectory() + "data/counts/count_{}Up.pkl".format(variation)) count = [] for c in cols: tempup = np.r_[dfup[c][0], dfup[c][1], dfup[c][2], dfup[c][3]] temp0 = np.r_[df0[c][0], df0[c][1], df0[c][2], df0[c][3]] count.append(tempup - temp0) counts[variation] = count # variate down for variation in ['EPt', 'MuPt', 'TauPt']: dfdw = pd.read_pickle(common.getBaseDirectory() + "data/counts/count_{}Down.pkl".format(variation)) count = [] for c in cols: tempdw = np.r_[dfdw[c][0], dfdw[c][1], dfdw[c][2], dfdw[c][3]] temp0 = np.r_[df0[c][0], df0[c][1], df0[c][2], df0[c][3]] count.append(temp0 - tempdw) counts[variation] = count # variate up-down for variation in ['JES', 'JER', 'BTag', "Mistag"]: dfdw = pd.read_pickle(common.getBaseDirectory() + "data/counts/count_{}Down.pkl".format(variation)) dfup = pd.read_pickle(common.getBaseDirectory() + "data/counts/count_{}Up.pkl".format(variation)) count = [] for c in cols: tempdw = np.r_[dfdw[c][0], dfdw[c][1], dfdw[c][2], dfdw[c][3]] tempup = np.r_[dfup[c][0], dfup[c][1], dfup[c][2], dfup[c][3]] count.append((tempup - tempdw) / 2) counts[variation] = count # lepton eff for variation in ['EffE', 'EffMu', 'EffTau']: if variation == 'EffE': effup = 1.01 effup = np.array([effup, 1, 1, 1] * 2 + [effup**2, effup, effup, effup] * 2) if variation == 'EffMu': effup = 1.01 effup = np.array([effup, effup**2, effup, effup] * 2 + [1, effup, 1, 1] * 2) if variation == 'EffTau': effup = 1.05 effup = np.array([1, 1, effup, 1] * 2 + [1, 1, effup, 1] * 2) count = [] for c in cols: temp0 = np.r_[df0[c][0], df0[c][1], df0[c][2], df0[c][3]] if c == 'acc': tempup = np.r_[df0[c][0], df0[c][1], df0[c][2], df0[c][3]] * effup.reshape(16, 1, 1) elif c == 'nmcbg': tempup = np.r_[df0[c][0], df0[c][1], df0[c][2], df0[c][3]] * effup.reshape(16, 1) else: tempup = np.r_[df0[c][0], df0[c][1], df0[c][2], df0[c][3]] count.append(tempup - temp0) counts[variation] = count # background xs for variation in ['VVXS', 'ZXS', 'WXS']: if variation == 'VVXS': effup = np.array([[1.1, 1, 1]]) if variation == 'EffMu': effup = np.array([[1, 1.05, 1]]) if variation == 'EffTau': effup = np.array([[1, 1, 1.05]]) count = [] for c in cols: temp0 = np.r_[df0[c][0], df0[c][1], df0[c][2], df0[c][3]] if c == 'nmcbg': tempup = np.r_[df0[c][0], df0[c][1], df0[c][2], df0[c][3]] * effup else: tempup = np.r_[df0[c][0], df0[c][1], df0[c][2], df0[c][3]] count.append(tempup - temp0) counts[variation] = count # fake rate for variation in ['fakee', 'fakemu', 'faketau']: if variation == 'fakee': effup = 1.25 effup = np.array([1, 1, 1, 1] * 2 + [1, 1, 1, effup] * 2) if variation == 'fakemu': effup = 1.25 effup = np.array([1, 1, 1, effup] * 2 + [1, 1, 1, 1] * 2) if variation == 'faketau': effup = 1.25 effup = np.array([1, 1, effup, 1] * 4) count = [] for c in cols: temp0 = np.r_[df0[c][0], df0[c][1], df0[c][2], df0[c][3]] if c == 'nfake': tempup = np.r_[df0[c][0], df0[c][1], df0[c][2], df0[c][3]] * effup else: tempup = np.r_[df0[c][0], df0[c][1], df0[c][2], df0[c][3]] count.append(tempup - temp0) counts[variation] = count counts = pd.DataFrame.from_dict(counts, orient='index', columns=cols) return counts
def _setConfiguration(self): self.outputPlotDir = None baseDirectory = common.getBaseDirectory() # MARK -- config output plot directory if self.nbjet == "==1": self.outputPlotDir = baseDirectory + "plots/kinematics/{}/1b/".format( self.selection) elif self.nbjet == ">1": self.outputPlotDir = baseDirectory + "plots/kinematics/{}/2b/".format( self.selection) elif self.nbjet == "<1": self.outputPlotDir = baseDirectory + "plots/kinematics/{}/0b/".format( self.selection) # MARK -- config plotting parameters for each selection # mumu if self.selection in ["mumu", "mumuc"]: self.mcsgQueryList = [ 'genCategory>=16', 'genCategory in [1,3,4,5,6,7,8,9,10,11,12]', 'genCategory in [2]', 'genCategory in [13,14,15]' ] self.labelList = [ 'Diboson', 'Z+Jets', 'W+Jets', r'$tt/tW \rightarrow$ other', r'$tt/tW \rightarrow ll$ other', r'$tt/tW \rightarrow \mu + \mu$', r'$tt/tW \rightarrow \mu+ \tau$', 'data' ] self.colorList = [ "#a32020", "#e0301e", "#eb8c00", "gold", "#49feec", "deepskyblue", "mediumpurple", "k" ] self.pp = pd.read_csv( baseDirectory + "scripts/plotterItemTables/itemTable_mumu.csv") self.adjust = [1, 1, 1, 1, 1, 1, 1] #self.hasFake = False # ee elif self.selection in ["ee", "eec"]: self.mcsgQueryList = [ 'genCategory>=16', 'genCategory in [2,3,4,5,6,7,8,9,13,14,15]', 'genCategory in [1]', 'genCategory in [10,11,12]' ] self.labelList = [ 'Diboson', 'Z+Jets', 'W+Jets', r'$tt/tW \rightarrow$ other', r'$tt/tW \rightarrow ll$ other', r'$tt/tW \rightarrow e + e$', r'$tt/tW \rightarrow e + \tau$', 'data' ] self.colorList = [ "#a32020", "#e0301e", "#eb8c00", "gold", "#49feec", "deepskyblue", "mediumpurple", "k" ] self.pp = pd.read_csv(baseDirectory + "scripts/plotterItemTables/itemTable_ee.csv") self.adjust = [1, 1, 1, 1, 1, 1, 1] #self.hasFake = False # mue and emu elif self.selection in ["emu", "emu2"]: self.mcsgQueryList = [ 'genCategory>=16', 'genCategory in [1,2,4,5,6,7,8,9]', 'genCategory in [3]', 'genCategory in [10,11,12]', 'genCategory in [13,14,15]' ] self.labelList = [ 'Diboson', 'Z+Jets', 'W+Jets', r'$tt/tW \rightarrow$ (other)', r'$tt/tW \rightarrow l + l$ (other)', r'$tt/tW \rightarrow e + \mu$', r'$tt/tW \rightarrow e + \tau$', r'$tt/tW \rightarrow \mu + \tau$', 'data' ] self.colorList = [ "#a32020", "#e0301e", "#eb8c00", "gold", "springgreen", "#49feec", "deepskyblue", "mediumpurple", "k" ] self.pp = pd.read_csv( baseDirectory + "scripts/plotterItemTables/itemTable_emu.csv") self.adjust = [1, 1, 1, 1, 1, 1, 1, 1] #self.hasFake = False # mutau elif "mutau" in self.selection: self.mcsgQueryList = [ 'genCategory in [16,21]', 'genCategory in [1,2,3, 4,5,6,7,8,9, 10,11,12]', 'genCategory in [17]', 'genCategory in [18,19,20]', 'genCategory in [13,14,15]' ] self.labelList = [ 'Diboson', 'Z+Jets', 'W+Jets', r'$tt/tW \rightarrow$ other', r'$tt/tW \rightarrow l + l$ (other) ', r'$tt/tW \rightarrow \mu + h$', r'$tt/tW \rightarrow \tau + h$', r'$tt/tW \rightarrow \mu + \tau$', 'data' ] self.colorList = [ "#a32020", "#e0301e", "#eb8c00", "gold", "springgreen", "#49feec", "deepskyblue", "mediumpurple", "k" ] self.pp = pd.read_csv( baseDirectory + "scripts/plotterItemTables/itemTable_mutau.csv") self.adjust = [1, 1, 1, 1, 1, 1, 1, 1, 1] #self.adjust = [1/.95,1/.95,1/.95,1/.95,1/.95,1/.95,.89/.95] #self.hasFake = False if self.selection == 'mutau': self.fakeSF = common.getFakeSF('tau') self.colorList = ['grey'] + self.colorList self.adjust = [self.fakeSF] + self.adjust self.labelList = ['Fakes'] + self.labelList # etau elif "etau" in self.selection: self.mcsgQueryList = [ 'genCategory in [17,21]', 'genCategory in [1,2,3, 4,5,6,7,8,9, 13,14,15]', 'genCategory in [16]', 'genCategory in [18,19,20]', 'genCategory in [10,11,12]' ] self.labelList = [ 'Diboson', 'Z+Jets', 'W+Jets', r'$tt/tW \rightarrow$ other', r'$tt/tW \rightarrow l + l$ (other) ', r'$tt/tW \rightarrow e + h$', r'$tt/tW \rightarrow \tau + h$', r'$tt/tW \rightarrow e + \tau$', 'data' ] self.colorList = [ "#a32020", "#e0301e", "#eb8c00", "gold", "springgreen", "#49feec", "deepskyblue", "mediumpurple", "k" ] self.pp = pd.read_csv( baseDirectory + "scripts/plotterItemTables/itemTable_etau.csv") self.adjust = [1, 1, 1, 1, 1, 1, 1, 1, 1] #self.adjust = [1/.95,1/.95,1/.95,1/.95,1/.95,1/.95,.89/.95] #self.hasFake = False if self.selection == 'etau': self.fakeSF = common.getFakeSF('tau') self.colorList = ['grey'] + self.colorList self.adjust = [self.fakeSF] + self.adjust self.labelList = ['Fakes'] + self.labelList # mu4j elif "mu4j" in self.selection: self.mcsgQueryList = [ 'genCategory in [16,18,19,20,21]', 'genCategory in [1,2,3,4,5,6,7,8,9,10,11,12]', 'genCategory in [17]', 'genCategory in [13,14,15]' ] self.labelList = [ 'Diboson', 'Z+Jets', 'W+Jets', r'$tt/tW \rightarrow$ other', r'$tt/tW \rightarrow ll$ other', r'$tt/tW \rightarrow \mu + h$', r'$tt/tW \rightarrow \mu + \tau$', 'data' ] self.pp = pd.read_csv( baseDirectory + "scripts/plotterItemTables/itemTable_mu4j.csv") self.colorList = [ "#a32020", "#e0301e", "#eb8c00", "gold", "#49feec", "deepskyblue", "mediumpurple", "k" ] self.adjust = [1, 1, 1, 1, 1, 1, 1] if self.selection == 'mu4j': self.fakeSF = common.getFakeSF('mu') self.colorList = ['grey'] + self.colorList self.adjust = [self.fakeSF] + self.adjust self.labelList = ['Fakes'] + self.labelList # e4j elif "e4j" in self.selection: self.mcsgQueryList = [ 'genCategory in [17,18,19,20,21]', 'genCategory in [1,2,3,4,5,6,7,8,9,13,14,15]', 'genCategory in [16]', 'genCategory in [10,11,12]' ] self.labelList = [ 'Diboson', 'Z+Jets', 'W+Jets', r'$tt/tW \rightarrow$ other', r'$tt/tW \rightarrow ll$ other', r'$tt/tW \rightarrow e + h$', r'$tt/tW \rightarrow e + \tau$', 'data' ] self.pp = pd.read_csv( baseDirectory + "scripts/plotterItemTables/itemTable_e4j.csv") self.colorList = [ "#a32020", "#e0301e", "#eb8c00", "gold", "#49feec", "deepskyblue", "mediumpurple", "k" ] self.adjust = [1, 1, 1, 1, 1, 1, 1] if self.selection == 'e4j': self.fakeSF = common.getFakeSF('e') self.colorList = ['grey'] + self.colorList self.adjust = [self.fakeSF] + self.adjust self.labelList = ['Fakes'] + self.labelList