def fillHistograms(self, d_histType, t_var, tFile, tName, sDir, t_muon, t_select, selectOn, nEvents): PythonUtils.Info('Filling Histograms: ' + tFile) f = TFile(tFile, 'READ') t = f.Get(tName) for i, entry in enumerate(t): ## only run over nEvents if nEvents != -1: if i == nEvents: break for sMu in t_muon: b_mu = 'nMu_' + sMu[0] + sMu[1] for bin in t_select: if bin[1]: select = selectOn + '-' + bin[0] + '-' + bin[1] else: select = selectOn + '-' + bin[0] for j in xrange(len(t_var)): rBranch, tBranch, sName, sLoc, xMin, xMax, nBins = t_var[ j] bSelect = '' if selectOn == 'TRUTH': bSelect = tBranch elif selectOn == 'RECO': bSelect = rBranch else: PythonUtils.Error('Option Not available') if sMu[0] == 'all' or PythonUtils.getSelection( entry, sMu[0], sMu[1], 'hasMuon'): if bin[0] == 'all' or PythonUtils.getSelection( entry, bin[0], bin[1], bSelect): location = sDir + '/' + b_mu + '/' + select + '/' + sLoc rValue = getattr(entry, rBranch) tValue = getattr(entry, tBranch) if 'cw' in location: d_histType[b_mu][select][ location + sName].Fill( tValue / rValue, entry.eventWeight) elif 'bw' in location: d_histType[b_mu][select][ location + sName].Fill( rValue / tValue, entry.eventWeight) elif 'vw' in location: d_histType[b_mu][select][ location + sName].Fill( rValue, entry.eventWeight) else: PythonUtils.Error( 'Histogram Type not recognised!') return d_histType
def main(): use = ''' Example: python PYTHON/MODULES/runProfile.py --MainConfigFile=ConfigFiles/Profile/MainConfigFile/MainConfigFile.cfg --doProfile=0 --createFile=0 ''' parser = OptionParser(usage=use) parser.add_option('--MainConfigFile', dest='MainConfigFile', default='', type='string', help='Main config file for creating profile plots') parser.add_option('--doProfile', dest='doProfile', default=0, type='int', help='Create the 2D profile plots ') parser.add_option('--createFile', dest='createFile', default=0, type='int', help='Create the histogram for the pT bins') options, args = parser.parse_args() if options.MainConfigFile: createProfile = CreateProfile(options.MainConfigFile, options.doProfile) createProfile.Run(options.doProfile, options.createFile) else: PythonUtils.Error('Configuration File NOT Found!!') print use sys.exit(1)
def Run(self): ## Make the list from the config file l_range = PythonUtils.makeListFromString(self.plotRange, ',') t_select = PythonUtils.makeTupleFromString(self.selectBins, ',', '?') ## Check the input and process files exist l_file = [self.processList, self.inputFile] for file in l_file: PythonUtils.doesFileExist(file) ## Loop over the ProcessList files f = open(self.processList, 'r') for line in f: if line.startswith('#'): continue l_process = PythonUtils.makeListFromString(line.strip(), ',') PythonUtils.doesFileExist(l_process[0]) t_process = PythonUtils.makeTupleFromFile(l_process[0], ',') l_yield = [] ##ll ll_VH = ['VH'] ll_VV = ['VV'] ll_top = ['top'] ll_stop = ['stop'] ll_Wl = ['W+l'] ll_Wcl = ['W+cl'] ll_Whf = ['W+hf'] ll_Zl = ['Z+l'] ll_Zcl = ['Z+cl'] ll_Zhf = ['Z+hf'] ll_MJe = ['MJe'] ll_MJm = ['MJm'] ll_tot = ['Total'] ll_data = ['Data'] for bin in t_select: if bin[0] == 'all': select = self.selectOn + '-' + bin[0] else: select = self.selectOn + '-' + bin[0] + '-' + bin[1] ## nEvents nSignal = 0 nTot = 0 nTop = 0 nStop = 0 nWl = 0 nWh = 0 nWcl = 0 nZl = 0 nZh = 0 nZcl = 0 nVV = 0 nMJe = 0 nMJm = 0 nData = 0 ##nEventsErr eSignal = 0 eTot = 0 eTop = 0 eStop = 0 eWl = 0 eWh = 0 eWcl = 0 eZl = 0 eZh = 0 eZcl = 0 eVV = 0 eMJe = 0 eMJm = 0 eData = 0 for i in xrange(len(t_process)): process, sLocation, pType, selection, SF = t_process[i] location = sLocation + '/all/' + select + '/' + self.histLocation hist = ROOTUtils.retrieveHistogram(self.inputFile, location, self.histogram) yValue, yErr = ROOTUtils.getYield(hist, l_range[0], l_range[1], t_process[i][4]) if pType == "SIGNAL": nTot += yValue nSignal += yValue eSignal += yErr eTot += yErr elif pType == "W+H": nTot += yValue nWh += yValue eWh += yErr eTot += yErr elif pType == "W+CL": nTot += yValue nWcl += yValue eWcl += yErr eTot += yErr elif pType == "W+L": nTot += yValue nWl += yValue eWl += yErr eTot += yErr elif pType == "Z+H": nTot += yValue nZh += yValue eZh += yErr eTot += yErr elif pType == "Z+CL": nTot += yValue nZcl += yValue eZcl += yErr eTot += yErr elif pType == "Z+L": nTot += yValue nZl += yValue eZl += yErr eTot += yErr elif pType == "TOP": nTot += yValue nTop += yValue eTop += yErr eTot += yErr elif pType == "STOP": nTot += yValue nStop += yValue nStop += yErr eTot += yErr elif pType == "VV": nTot += yValue nVV += yValue eVV += yErr eTot += yErr elif pType == "MJe": nTot += yValue nMJe += yValue nMJe += yErr eTot += yErr elif pType == "MJm": nTot += yValue nMJm += yValue eMJm += yErr eTot += yErr elif pType == "DATA": nData += yValue eData += yErr else: PythonUtils.Error('Not a valid selection: ' + t_process[i][2] + '!!!\n') l_VH = [nSignal, eSignal] ll_VH.append(l_VH) l_VV = [nVV, eVV] ll_VV.append(l_VV) l_top = [nTop, eTop] ll_top.append(l_top) l_stop = [nStop, eStop] ll_stop.append(l_stop) l_Wl = [nWl, eWl] ll_Wl.append(l_Wl) l_Wcl = [nWcl, eWcl] ll_Wcl.append(l_Wcl) l_Whf = [nWh, eWh] ll_Whf.append(l_Whf) l_Zl = [nZl, eZl] ll_Zl.append(l_Zl) l_Zcl = [nZcl, eZcl] ll_Zcl.append(l_Zcl) l_Zhf = [nZh, eZh] ll_Zhf.append(l_Zhf) l_MJe = [nMJe, eMJe] ll_MJe.append(l_MJe) l_MJm = [nMJm, eMJm] ll_MJm.append(l_MJm) l_tot = [nTot, eTot] ll_tot.append(l_tot) l_data = [nData, eData] ll_data.append(l_data) l_yield = [ ll_VH, ll_VV, ll_top, ll_stop, ll_Wl, ll_Wcl, ll_Whf, ll_Zl, ll_Zcl, ll_Zhf, ll_MJe, ll_MJm, ll_tot, ll_data ] self.printToScreen(l_yield, select + ' ' + t_process[i][3]) if self.createTex: texFile = self.saveToTex(l_yield, l_process[1], self.outputFile) self.runLatex(self.outputFile, texFile)