def PlotHistogram(dsetMgr, histoName, opts): # Get kistogram argumetns kwargs = GetHistoKwargs(histoName, opts) saveName = histoName.replace(opts.folder + "/", "") # Create the plotting object (Data, "FakeB") p1 = plots.DataMCPlot(dsetMgr, histoName, saveFormats=[]) # Copy dataset manager before changing datasets. Keep only EWK (GenuineB) datasets datasetMgr = dsetMgr.deepCopy() datasetMgr.selectAndReorder(aux.GetListOfEwkDatasets()) # Create the MCPlot for the EWKGenuineB histograms if opts.useMC: p2 = plots.MCPlot(datasetMgr, histoName, normalizeToLumi=opts.intLumi, saveFormats=[]) else: histoNameGenuineB = histoName.replace(opts.folder, opts.folder + "EWKGenuineB") p2 = plots.MCPlot(datasetMgr, histoNameGenuineB, normalizeToLumi=opts.intLumi, saveFormats=[]) # Add the datasets to be included in the plot myStackList = [] # Data-driven FakeB background if not opts.useMC: hFakeB = p1.histoMgr.getHisto("FakeB").getRootHisto() hhFakeB = histograms.Histo(hFakeB, "FakeB", legendLabel="Fake-b") hhFakeB.setIsDataMC(isData=False, isMC=True) myStackList.append(hhFakeB) else: hQCD = p1.histoMgr.getHisto("QCD").getRootHisto() hhQCD = histograms.Histo(hQCD, "QCD", legendLabel="QCD") hhQCD.setIsDataMC(isData=False, isMC=True) myStackList.append(hhQCD) # EWK GenuineB background (Replace all EWK histos with GenuineB histos) ewkHistoList = [] # For-loop: All EWK datasets for dataset in aux.GetListOfEwkDatasets(): h = p2.histoMgr.getHisto(dataset).getRootHisto() hh = histograms.Histo(h, dataset, plots._legendLabels[dataset]) hh.setIsDataMC(isData=False, isMC=True) myStackList.append(hh) # Collision data hData = p1.histoMgr.getHisto("Data").getRootHisto() hhData = histograms.Histo(hData, "Data") hhData.setIsDataMC(isData=True, isMC=False) myStackList.insert(0, hhData) # Signal hSignal = p1.histoMgr.getHisto(opts.signal).getRootHisto() hhSignal = histograms.Histo(hSignal, opts.signal, plots._legendLabels[opts.signal]) hhSignal.setIsDataMC(isData=False, isMC=True) myStackList.insert(1, hhSignal) # Create the final plot by passing the histogram list p3 = plots.DataMCPlot2(myStackList, saveFormats=[]) p3.setLuminosity(opts.intLumi) p3.setDefaultStyles() # Apply blinding of data in Signal Region (After creating the plot) if "blindingRangeString" in kwargs: startBlind = float(kwargs["blindingRangeString"].split("-")[1]) endBlind = float(kwargs["blindingRangeString"].split("-")[0]) plots.partiallyBlind(p3, maxShownValue=startBlind, minShownValue=endBlind, invert=True, moveBlindedText=kwargs["moveBlindedText"]) # Draw and save the plot plots.drawPlot(p3, saveName, **kwargs) SavePlot(p3, saveName, os.path.join(opts.saveDir, opts.optMode), saveFormats = [".png", ".pdf"]) return
def main(opts): # Apply TDR style style = tdrstyle.TDRStyle() style.setGridX(False) style.setGridY(False) style.setOptStat(False) # Obtain dsetMgrCreator and register it to module selector dsetMgrCreator = dataset.readFromMulticrabCfg(directory=opts.mcrab) # Get list of eras, modes, and optimisation modes erasList = dsetMgrCreator.getDataEras() modesList = dsetMgrCreator.getSearchModes() optList = dsetMgrCreator.getOptimizationModes() sysVarList = dsetMgrCreator.getSystematicVariations() sysVarSrcList = dsetMgrCreator.getSystematicVariationSources() # If user does not define optimisation mode do all of them if opts.optMode == None: if len(optList) < 1: optList.append("") optModes = optList else: optModes = [opts.optMode] # For-loop: All opt Mode for opt in optModes: opts.optMode = opt # Setup & configure the dataset manager datasetsMgr = GetDatasetsFromDir(opts) datasetsMgr.updateNAllEventsToPUWeighted() datasetsMgr.loadLuminosities() # from lumi.json if opts.verbose: datasetsMgr.PrintCrossSections() datasetsMgr.PrintLuminosities() # Get the PSets: if 0: datasetsMgr.printSelections() #PrintPSet("BJetSelection", datasetsMgr, depth=150) #PrintPSet("fakeBMeasurement", datasetsMgr, depth=150) sys.exit() # ZJets and DYJets overlap! if "ZJetsToQQ_HT600toInf" in datasetsMgr.getAllDatasetNames( ) and "DYJetsToQQ_HT180" in datasetsMgr.getAllDatasetNames(): Print( "Cannot use both ZJetsToQQ and DYJetsToQQ due to duplicate events? Investigate. Removing ZJetsToQQ datasets for now ..", True) datasetsMgr.remove( filter(lambda name: "ZJetsToQQ" in name, datasetsMgr.getAllDatasetNames())) # Merge histograms (see NtupleAnalysis/python/tools/plots.py) plots.mergeRenameReorderForDataMC(datasetsMgr) # Get luminosity if a value is not specified if opts.intLumi < 0: opts.intLumi = datasetsMgr.getDataset("Data").getLuminosity() # Remove datasets removeList = ["QCD-b", "Charged"] if not opts.useMC: removeList.append("QCD") for i, d in enumerate(removeList, 0): msg = "Removing dataset %s" % d Verbose( ShellStyles.WarningLabel() + msg + ShellStyles.NormalStyle(), i == 0) datasetsMgr.remove( filter(lambda name: d in name, datasetsMgr.getAllDatasetNames())) # Print summary of datasets to be used if 0: datasetsMgr.PrintInfo() # Merge EWK samples datasetsMgr.merge("EWK", aux.GetListOfEwkDatasets()) # Print dataset information datasetsMgr.PrintInfo() # List of TDirectoryFile (_CRone, _CRtwo, _VR, _SR) tdirs = [ "LdgTrijetPt_", "LdgTrijetMass_", "TetrajetBJetPt_", "TetrajetBJetEta_", "LdgTetrajetPt_", "LdgTetrajetMass_" ] region = ["CRone", "CRtwo"] hList = [] for d in tdirs: for r in region: hList.append(d + r) # Get the folders with the binned histograms folderList_ = datasetsMgr.getDataset( datasetsMgr.getAllDatasetNames()[0]).getDirectoryContent( opts.folder) folderList = [h for h in folderList_ if h in hList] # For-loop: All folders histoPaths = [] for f in folderList: folderPath = os.path.join(opts.folder, f) histoList = datasetsMgr.getDataset( datasetsMgr.getAllDatasetNames()[0]).getDirectoryContent( folderPath) pathList = [os.path.join(folderPath, h) for h in histoList] histoPaths.extend(pathList) # Get all the bin labels binLabels = GetBinLabels("CRone", histoPaths) for i, t in enumerate(tdirs, 1): myList = [] for p in histoPaths: if t in p: myList.append(p) msg = "{:<9} {:>3} {:<1} {:<3} {:<50}".format( "Histogram", "%i" % i, "/", "%s:" % (len(tdirs)), t.replace("_", "")) Print(ShellStyles.SuccessStyle() + msg + ShellStyles.NormalStyle(), i == 1) PlotHistograms(datasetsMgr, myList, binLabels, opts) # Save the plots Print( "All plots saved under directory %s" % (ShellStyles.NoteStyle() + aux.convertToURL(opts.saveDir, opts.url) + ShellStyles.NormalStyle()), True) return
def main(opts): # Apply TDR style style = tdrstyle.TDRStyle() style.setOptStat(False) style.setGridX(opts.gridX) style.setGridY(opts.gridY) style.setLogX(opts.logX) # If you want BOTH pads (main and ratio) in log scale if 0: style.setLogY(opts.logY) # Overwrite default legends plots._legendLabels["MCStatError"] = "Bkg. stat." plots._legendLabels["MCStatSystError"] = "Bkg. stat.#oplussyst." plots._legendLabels["BackgroundStatError"] = "Bkg. stat. unc" plots._legendLabels["BackgroundStatSystError"] = "Bkg. stat.#oplussyst. unc." # Define optimisatio modes to run on optModes = [""] #["", "OptChiSqrCutValue50", "OptChiSqrCutValue100"] if opts.optMode != None: optModes = [opts.optMode] # Inform user of EWK datasets used Print("The EWK datasets used are the following:", True) for i,d in enumerate(aux.GetListOfEwkDatasets(), 1): Print(ShellStyles.NoteStyle() + d + ShellStyles.NormalStyle(), i==0) # For-loop: All opt Mode for opt in optModes: opts.optMode = opt # Setup & configure the dataset manager dsetMgr1 = GetDatasetsFromDir(opts, False) dsetMgr2 = GetDatasetsFromDir(opts, True) # Setup the dataset managers dsetMgr1.updateNAllEventsToPUWeighted() dsetMgr2.updateNAllEventsToPUWeighted() # Load luminosities dsetMgr1.loadLuminosities() # from lumi.json # dsetMgr2.loadLuminosities() # Print PSets. Perhaps i can use this to ensure parameters are matching! if 0: dsetMgr1.printSelections() dsetMgr2.printSelections() PrintPSet("FakeBMeasurement", dsetMgr1) PrintPSet("TopSelectionBDT" , dsetMgr2) # Remove datasets with overlap? removeList = ["QCD-b"] dsetDY = "DYJetsToQQ_HT180" dsetZJ = "ZJetsToQQ_HT600toInf" dsetRM = dsetZJ # datasets with overlap removeList.append(dsetRM) # Set/Overwrite cross-sections. Remove all but 1 signal mass for d in dsetMgr1.getAllDatasets(): if "ChargedHiggs" in d.getName(): dsetMgr1.getDataset(d.getName()).setCrossSection(1.0) # ATLAS 13 TeV H->tb exclusion limits if d.getName() != opts.signal: removeList.append(d.getName()) # Print useful information? if opts.verbose: dsetMgr1.PrintCrossSections() dsetMgr1.PrintLuminosities() dsetMgr2.PrintCrossSections() dsetMgr2.PrintLuminosities() # Merge histograms plots.mergeRenameReorderForDataMC(dsetMgr1) # Get the luminosity if opts.intLumi < 0: opts.intLumi = dsetMgr1.getDataset("Data").getLuminosity() # Custom Filtering of datasets for i, d in enumerate(removeList, 1): msg = "Removing datasets %s from dataset manager" % (ShellStyles.NoteStyle() + d + ShellStyles.NormalStyle()) Verbose(msg, i==1) dsetMgr1.remove(filter(lambda name: d == name, dsetMgr1.getAllDatasetNames())) # Print dataset information dsetMgr1.PrintInfo() dsetMgr2.PrintInfo() # Replace MC datasets with data-driven if not opts.useMC: replaceQCD(dsetMgr1, dsetMgr2, "FakeBMeasurementTrijetMass", "FakeB") #dsetMgr1 now contains "FakeB" pseudo-dataset # Definitions allHistos = dsetMgr2.getAllDatasets()[0].getDirectoryContent(opts.folder) histoPaths = [] ignoreKeys = ["MCEWK", "Purity", "BJetPt", "BJetEta", "BtagDiscriminator", "METPhi", "MHT", "NBjets", "Njets", "_Vs_", "JetEta"] # For-loop: All histograms in directory for h in allHistos: bKeep = True for k in ignoreKeys: if k in h: bKeep = False continue if bKeep: histoPaths.append(os.path.join(opts.folder, h)) # For-loop: All histograms in list for i, hName in enumerate(histoPaths, 1): msg = "{:<9} {:>3} {:<1} {:<3} {:<50}".format("Histogram", "%i" % i, "/", "%s:" % (len(histoPaths)), hName) Print(ShellStyles.SuccessStyle() + msg + ShellStyles.NormalStyle(), i==1) PlotHistogram(dsetMgr1, hName, opts) Print("All plots saved under directory %s" % (ShellStyles.NoteStyle() + aux.convertToURL(opts.saveDir, opts.url) + ShellStyles.NormalStyle()), True) return
def main(opts): # Apply TDR style style = tdrstyle.TDRStyle() style.setOptStat(False) style.setGridX(True) #opts.gridX) style.setGridY(True) #opts.gridY) style.setLogX(False) #opts.logX) style.setLogY(False) #opts.logY) # Obtain dsetMgrCreator and register it to module selector dsetMgrCreator = dataset.readFromMulticrabCfg(directory=opts.mcrab) # Get list of eras, modes, and optimisation modes erasList = dsetMgrCreator.getDataEras() modesList = dsetMgrCreator.getSearchModes() optList = dsetMgrCreator.getOptimizationModes() sysVarList = dsetMgrCreator.getSystematicVariations() sysVarSrcList = dsetMgrCreator.getSystematicVariationSources() # If user does not define optimisation mode do all of them if opts.optMode == None: if len(optList) < 1: optList.append("") else: pass optModes = optList else: optModes = [opts.optMode] # For-loop: All optimisation modes for opt in optModes: opts.optMode = opt # Setup & configure the dataset manager datasetsMgr = GetDatasetsFromDir(opts) datasetsMgr.updateNAllEventsToPUWeighted() datasetsMgr.loadLuminosities() # from lumi.json if 0: datasetsMgr.printSelections() # Set/Overwrite cross-sections for d in datasetsMgr.getAllDatasets(): if "ChargedHiggs" in d.getName(): datasetsMgr.getDataset(d.getName()).setCrossSection(1.0) if opts.verbose: datasetsMgr.PrintCrossSections() datasetsMgr.PrintLuminosities() # Custom Filtering of datasets if 0: datasetsMgr.remove(filter(lambda name: "Charged" in name and not "M_500" in name, datasetsMgr.getAllDatasetNames())) # ZJets and DYJets overlap! if "ZJetsToQQ_HT600toInf" in datasetsMgr.getAllDatasetNames() and "DYJetsToQQ_HT180" in datasetsMgr.getAllDatasetNames(): Print("Cannot use both ZJetsToQQ and DYJetsToQQ due to duplicate events? Investigate. Removing ZJetsToQQ datasets for now ..", True) datasetsMgr.remove(filter(lambda name: "ZJetsToQQ" in name, datasetsMgr.getAllDatasetNames())) # Merge histograms (see NtupleAnalysis/python/tools/plots.py) plots.mergeRenameReorderForDataMC(datasetsMgr) datasetsMgr.PrintInfo() # Get Luminosity if opts.intLumi < 0.0: if "Data" in datasetsMgr.getAllDatasetNames(): opts.intLumi = datasetsMgr.getDataset("Data").getLuminosity() else: opts.intLumi = 1.0 # Merge EWK samples if opts.dataset == "EWK": datasetsMgr.merge("EWK", aux.GetListOfEwkDatasets()) plots._plotStyles["EWK"] = styles.getAltEWKStyle() # Print dataset information datasetsMgr.PrintInfo() # Get all histogram names in the given ROOT folder histoNames = datasetsMgr.getAllDatasets()[0].getDirectoryContent(opts.folder) # histoList = [os.path.join(opts.folder, h) for h in histoNames if "_" + opts.region in h and opts.refBdisc in h] histoList = [os.path.join(opts.folder, h) for h in histoNames if opts.refBdisc in h] # For-loop: All histos in CR of interest nHistos = len(histoList) for i, h in enumerate(histoList, 1): msg = "{:<9} {:>3} {:<1} {:<3} {:<50}".format("Histogram", "%i" % i,"/", "%s:" % (nHistos), h) Print(ShellStyles.SuccessStyle() + msg + ShellStyles.NormalStyle(), i==1) PlotHistograms(datasetsMgr, h) # Inform user where the plots where saved Print("All plots saved under directory %s" % (ShellStyles.NoteStyle() + aux.convertToURL(opts.saveDir, opts.url) + ShellStyles.NormalStyle()), True) return
def main(opts): # Apply TDR style style = tdrstyle.TDRStyle() style.setGridX(opts.gridX) style.setGridY(opts.gridY) # Obtain dsetMgrCreator and register it to module selector dsetMgrCreator = dataset.readFromMulticrabCfg(directory=opts.mcrab) # Get list of eras, modes, and optimisation modes erasList = dsetMgrCreator.getDataEras() modesList = dsetMgrCreator.getSearchModes() optList = dsetMgrCreator.getOptimizationModes() sysVarList = dsetMgrCreator.getSystematicVariations() sysVarSrcList = dsetMgrCreator.getSystematicVariationSources() # If user does not define optimisation mode do all of them if opts.optMode == None: if len(optList) < 1: optList.append("") else: pass optModes = optList else: optModes = [opts.optMode] # For-loop: All optimisation modes for opt in optModes: opts.optMode = opt # Setup & configure the dataset manager datasetsMgr = GetDatasetsFromDir(opts) datasetsMgr.updateNAllEventsToPUWeighted() datasetsMgr.loadLuminosities() # from lumi.json # Print PSets used for FakeBMeasurement if 0: datasetsMgr.printSelections() # Set/Overwrite cross-sections for d in datasetsMgr.getAllDatasets(): if "ZJetsToQQ_HT600toInf" in d.getName(): datasetsMgr.remove(d.getName()) if "ChargedHiggs" in d.getName(): datasetsMgr.getDataset(d.getName()).setCrossSection(1.0) if d.getName() not in opts.signal: if not opts.acceptance: datasetsMgr.remove(d.getName()) if opts.verbose: datasetsMgr.PrintCrossSections() datasetsMgr.PrintLuminosities() datasetsMgr.PrintInfo() # Merge histograms (see NtupleAnalysis/python/tools/plots.py) plots.mergeRenameReorderForDataMC(datasetsMgr) # Get Luminosity # For acceptance plot use all available masses if opts.acceptance: opts.signal = [] opts.signalMasses = [] for d in datasetsMgr.getAllDatasets(): if "ChargedHiggs" in d.getName(): #dName = d.getName().replace("_ext1", "").split("M_") dName = d.getName().split("M_") m = int(dName[-1]) opts.signal.append(d.getName()) opts.signalMasses.append(m) if opts.intLumi < 0: if "Data" in datasetsMgr.getAllDatasetNames(): opts.intLumi = datasetsMgr.getDataset("Data").getLuminosity() else: opts.intLumi = 1.0 # Merge EWK samples if 1: datasetsMgr.merge("EWK", aux.GetListOfEwkDatasets()) plots._plotStyles["EWK"] = styles.getAltEWKStyle() # Print post EWK-merge dataset summary datasetsMgr.PrintInfo() # Get the efficiency graphs hGraphList = [] histoName = os.path.join(opts.folder, "counter") hGraphList, _kwargs = GetHistoGraphs(datasetsMgr, opts.folder, histoName) # Plot the histo graphs PlotHistoGraphs(hGraphList, _kwargs) Print( "All plots saved under directory %s" % (ShellStyles.NoteStyle() + aux.convertToURL(opts.saveDir, opts.url) + ShellStyles.NormalStyle()), True) return
def main(opts): optModes = [""] if opts.optMode != None: optModes = [opts.optMode] # For-loop: All opt Mode for opt in optModes: opts.optMode = opt # Setup & configure the dataset manager datasetsMgr = GetDatasetsFromDir(opts) datasetsMgr.updateNAllEventsToPUWeighted() datasetsMgr.loadLuminosities(fname="lumi.json") # Get Luminosity if opts.intLumi < 0: if "Data" in datasetsMgr.getAllDatasetNames(): opts.intLumi = datasetsMgr.getDataset("Data").getLuminosity() else: opts.intLumi = datasetsMgr.loadLumi() # Set/Overwrite cross-sections datasetsToRemove = [] for d in datasetsMgr.getAllDatasets(): mass = "M_%s" % (opts.signalMass) if mass in d.getName(): if ("%s" % opts.signalMass) != d.getName().split("M_")[-1]: datasetsMgr.remove(d.getName()) else: datasetsMgr.getDataset(d.getName()).setCrossSection(1.0) else: #datasetsToRemove.append(d.getName()) datasetsMgr.remove(d.getName()) if opts.verbose: datasetsMgr.PrintCrossSections() datasetsMgr.PrintLuminosities() # Merge histograms (see NtupleAnalysis/python/tools/plots.py) plots.mergeRenameReorderForDataMC(datasetsMgr) # # Custom Filtering of datasets # for i, d in enumerate(datasetsToRemove, 0): # msg = "Removing dataset %s" % d # Verbose(ShellStyles.WarningLabel() + msg + ShellStyles.NormalStyle(), i==0) # datasetsMgr.remove(filter(lambda name: d == name, datasetsMgr.getAllDatasetNames())) if opts.verbose: datasetsMgr.PrintInfo() # Merge EWK samples if opts.mergeEWK: datasetsMgr.merge("EWK", aux.GetListOfEwkDatasets()) plots._plotStyles["EWK"] = styles.getAltEWKStyle() # Print dataset information datasetsMgr.PrintInfo() # Apply TDR style style = tdrstyle.TDRStyle() style.setOptStat(True) style.setGridX(opts.gridX) style.setGridY(opts.gridY) # Do Data-MC histograms with DataDriven QCD folder = opts.folder histoList = datasetsMgr.getDataset( datasetsMgr.getAllDatasetNames()[0]).getDirectoryContent(folder) histoPaths = [os.path.join(folder, h) for h in histoList] keepList = ["LdgTetrajetMass_AfterAllSelections"] #keepList = ["LdgTetrajetMass_AfterStandardSelections"] myHistos = [] for h in histoPaths: if h.split("/")[-1] not in keepList: continue else: myHistos.append(h) for i, h in enumerate(myHistos, 1): PlotHistograms(datasetsMgr, h) Print( "All plots saved under directory %s" % (ShellStyles.NoteStyle() + aux.convertToURL(opts.saveDir, opts.url) + ShellStyles.NormalStyle()), True) return
def main(opts): # Apply TDR style style = tdrstyle.TDRStyle() style.setOptStat(False) style.setGridX(False) style.setGridY(False) # Obtain dsetMgrCreator and register it to module selector dsetMgrCreator = dataset.readFromMulticrabCfg(directory=opts.mcrab1) # Get list of eras, modes, and optimisation modes erasList = dsetMgrCreator.getDataEras() modesList = dsetMgrCreator.getSearchModes() optList = dsetMgrCreator.getOptimizationModes() sysVarList = dsetMgrCreator.getSystematicVariations() sysVarSrcList = dsetMgrCreator.getSystematicVariationSources() # If user does not define optimisation mode do all of them if opts.optMode == None: optModes = optList else: optModes = [opts.optMode] # For-loop: All optimisation modes for opt in optModes: opts.optMode = opt # Get the datasets from the directory datasetsMgr1 = GetDatasetsFromDir(opts.mcrab1, opts) datasetsMgr2 = GetDatasetsFromDir(opts.mcrab2, opts) datasetsMgr3 = GetDatasetsFromDir(opts.mcrab3, opts) # Setup the dataset managers datasetsMgr1.updateNAllEventsToPUWeighted() datasetsMgr1.loadLuminosities() # from lumi.json datasetsMgr2.updateNAllEventsToPUWeighted() datasetsMgr2.loadLuminosities() # from lumi.json datasetsMgr3.updateNAllEventsToPUWeighted() datasetsMgr3.loadLuminosities() # from lumi.json # Print dataset info? if opts.verbose: datasetsMgr1.PrintCrossSections() datasetsMgr1.PrintLuminosities() datasetsMgr2.PrintCrossSections() datasetsMgr2.PrintLuminosities() datasetsMgr2.PrintCrossSections() datasetsMgr2.PrintLuminosities() # Merge histograms (see NtupleAnalysis/python/tools/plots.py) plots.mergeRenameReorderForDataMC(datasetsMgr1) plots.mergeRenameReorderForDataMC(datasetsMgr2) plots.mergeRenameReorderForDataMC(datasetsMgr3) # Get Luminosity lumi1 = datasetsMgr1.getDataset("Data").getLuminosity() lumi2 = datasetsMgr2.getDataset("Data").getLuminosity() lumi3 = datasetsMgr3.getDataset("Data").getLuminosity() if lumi1 != lumi2 != lumi3: raise Exception("Lumi1 (=%.2f) != Lumi2 (=%.2f) != Lumi3 (=%.2f" % (lumi1, lumi2, lumi3)) else: opts.intLumi = datasetsMgr1.getDataset("Data").getLuminosity() # Merge EWK samples datasetsMgr1.merge("EWK", aux.GetListOfEwkDatasets()) datasetsMgr2.merge("EWK", aux.GetListOfEwkDatasets()) datasetsMgr3.merge("EWK", aux.GetListOfEwkDatasets()) plots._plotStyles["EWK"] = styles.getAltEWKStyle() # Print dataset information datasetsMgr1.PrintInfo() if 0: datasetsMgr2.PrintInfo() datasetsMgr3.PrintInfo() # Get all the histograms and their paths (e.g. ForFakeBMeasurement/Baseline_DeltaRLdgTrijetBJetTetrajetBJet_AfterCRSelections) hList = datasetsMgr1.getDataset( datasetsMgr1.getAllDatasetNames()[0]).getDirectoryContent( opts.folder) hPaths = [os.path.join(opts.folder, h) for h in hList] # Create a smaller list with only histos of interest hListS = [] for h in hList: if "StandardSelections" in h: continue if "IsGenuineB" in h: continue if "_Bjet" in h: continue if "_Jet" in h: continue if "_SubLdg" in h: continue if "_Njets" in h: continue if "_NBjets" in h: continue if "_Delta" in h: continue if "Dijet" in h: continue if "Bdisc" in h: continue #if "MVA" in h: # continue if "MET" in h: continue if "HT" in h: continue # Otherwise keep the histogram hListS.append(h) hPathsS = [os.path.join(opts.folder, h) for h in hListS] # Create two lists of paths: one for "Baseline" (SR) and one for "Inverted" (CR) path_SR = [] # baseline, _AfterAllSelections path_CR1 = [] # baseline, _AfterCRSelections path_VR = [] # inverted, _AfterAllSelections path_CR2 = [] # inverted, _AfterCRSelections # For-loop: All histogram paths for p in hPathsS: #hPaths: if "Baseline" in p: if "AllSelections" in p: path_SR.append(p) if "CRSelections" in p: path_CR1.append(p) if "Inverted" in p: if "AllSelections" in p: path_VR.append(p) if "CRSelections" in p: path_CR2.append(p) counter = 1 # For-loop: All histogram pairs for hCR1, hCR2 in zip(path_CR1, path_CR2): if "IsGenuineB" in hCR1: continue #hName = hCR1.replace("_AfterCRSelections", "_CR1vCR2").replace("ForFakeBMeasurement/Baseline_", "") hName = hCR1.replace("_AfterCRSelections", " (CR1 and R2)").replace( "ForFakeBMeasurement/Baseline_", "") msg = "{:<9} {:>3} {:<1} {:<3} {:<50}".format( "Histogram", "%i" % counter, "/", "%s:" % (len(path_CR1)), hName) Print(ShellStyles.SuccessStyle() + msg + ShellStyles.NormalStyle(), counter == 1) PlotComparison(datasetsMgr1, datasetsMgr2, datasetsMgr3, hCR1, hCR2, "CR1") PlotComparison(datasetsMgr1, datasetsMgr2, datasetsMgr3, hCR1, hCR2, "CR2") #iro counter += 1 # WARNING! This unblinds the Signal Region (SR) for hSR, hVR in zip(path_SR, path_VR): if "IsGenuineB" in hSR: continue if 1: continue #hName = hCR1.replace("_AfterCRSelections", "_SRvVR").replace("ForFakeBMeasurement/Baseline_", "") hName = hCR1.replace("_AfterCRSelections", " (SR and VR)").replace( "ForFakeBMeasurement/Baseline_", "") msg = "{:<9} {:>3} {:<1} {:<3} {:<50}".format( "Histogram", "%i" % counter, "/", "%s:" % (len(path_CR1)), hName) Print(ShellStyles.SuccessStyle() + msg + ShellStyles.NormalStyle(), counter == 1) PlotComparison(datasetsMgr1, datasetsMgr2, datasetsMgr3, hSR, hVR, "SR") PlotComparison(datasetsMgr1, datasetsMgr2, datasetsMgr3, hSR, hVR, "VR") counter += 1 Print( "All plots saved under directory %s" % (ShellStyles.NoteStyle() + aux.convertToURL(opts.saveDir, opts.url) + ShellStyles.NormalStyle()), True) return
def main(opts): #optModes = ["", "OptChiSqrCutValue50", "OptChiSqrCutValue100"] optModes = [""] if opts.optMode != None: optModes = [opts.optMode] # For-loop: All opt Mode for opt in optModes: opts.optMode = opt # Setup & configure the dataset manager datasetsMgr = GetDatasetsFromDir(opts) datasetsMgr.updateNAllEventsToPUWeighted() datasetsMgr.loadLuminosities() # from lumi.json datasetsMgr_matched = GetDatasetsFromDir(opts) datasetsMgr_matched.updateNAllEventsToPUWeighted() datasetsMgr_matched.loadLuminosities() # from lumi.json plots.mergeRenameReorderForDataMC(datasetsMgr) datasetsMgr.remove(filter(lambda name: "QCD_b" in name, datasetsMgr.getAllDatasetNames())) #soti datasetsMgr_matched.remove(filter(lambda name: "QCD" in name, datasetsMgr_matched.getAllDatasetNames())) #soti # Set/Overwrite cross-sections datasetsToRemove = ["QCD-b"]#, "QCD_HT50to100", "QCD_HT100to200"]#, "QCD_HT200to300"]#, "QCD_HT300to500"] for d in datasetsMgr.getAllDatasets(): if "ChargedHiggs" in d.getName(): datasetsMgr.getDataset(d.getName()).setCrossSection(1.0) # ATLAS 13 TeV H->tb exclusion limits #if d.getName() != opts.signal: if "M_650" in d.getName(): #soti fixmi datasetsToRemove.append(d.getName()) if "M_800" in d.getName(): datasetsToRemove.append(d.getName()) if "M_200" in d.getName(): datasetsToRemove.append(d.getName()) if opts.verbose: datasetsMgr.PrintCrossSections() datasetsMgr.PrintLuminosities() # Custom Filtering of datasets for i, d in enumerate(datasetsToRemove, 0): msg = "Removing dataset %s" % d Print(ShellStyles.WarningLabel() + msg + ShellStyles.NormalStyle(), i==0) datasetsMgr.remove(filter(lambda name: d in name, datasetsMgr.getAllDatasetNames())) datasetsMgr_matched.remove(filter(lambda name: d in name, datasetsMgr_matched.getAllDatasetNames())) #soti if opts.verbose: datasetsMgr.PrintInfo() # ZJets and DYJets overlap if "ZJetsToQQ_HT600toInf" in datasetsMgr.getAllDatasetNames() and "DYJetsToQQ_HT180" in datasetsMgr.getAllDatasetNames(): Print("Cannot use both ZJetsToQQ and DYJetsToQQ due to duplicate events? Investigate. Removing ZJetsToQQ datasets for now ..", True) datasetsMgr.remove(filter(lambda name: "ZJetsToQQ" in name, datasetsMgr.getAllDatasetNames())) #datasetsMgr.merge("QCD", GetListOfQCDatasets()) #plots._plotStyles["QCD"] = styles.getQCDLineStyle() # Merge histograms (see NtupleAnalysis/python/tools/plots.py) # Get Luminosity #intLumi = datasetsMgr.getDataset("Data").getLuminosity() Soti intLumi = 35920 # Re-order datasets (different for inverted than default=baseline) newOrder = [] # For-loop: All MC datasets for d in datasetsMgr.getMCDatasets(): newOrder.append(d.getName()) # Move signal to top # if opts.signal in newOrder: # s = newOrder.pop( newOrder.index(opts.signal) ) # newOrder.insert(0, s) print len(newOrder), "newOrder" signalMass = ["M_300", "M_500", "M_1000"] for d in datasetsMgr.getMCDatasets(): for m in signalMass: if m in d.getName(): s = newOrder.pop( newOrder.index(d.getName()) ) newOrder.insert(0, s) #datasetsMgr.selectAndReorder(newOrder) print len(newOrder), "newOrder" # Add Data to list of samples! if not opts.onlyMC: newOrder.insert(0, "Data") # Apply new dataset order! datasetsMgr.selectAndReorder(newOrder) # Merge EWK samples if opts.mergeEWK: datasetsMgr.merge("EWK", aux.GetListOfEwkDatasets()) plots._plotStyles["EWK"] = styles.getAltEWKStyle() # Print dataset information datasetsMgr.PrintInfo() # Apply TDR style style = tdrstyle.TDRStyle() style.setOptStat(True) style.setGridX(opts.gridX) style.setGridY(opts.gridY) # Do Data-MC histograms with DataDriven QCD folder = opts.folder histoList = datasetsMgr.getDataset(datasetsMgr.getAllDatasetNames()[0]).getDirectoryContent(folder) histoPaths1 = [os.path.join(folder, h) for h in histoList] histoPaths2 = [h for h in histoPaths1]# if "jet" not in h.lower()] nHistos = len(histoPaths2) # For-loop: All histograms for i, h in enumerate(histoPaths2, 1): msg = "{:<9} {:>3} {:<1} {:<3} {:<50}".format("Histogram", "%i" % i, "/", "%s:" % (nHistos), h) Print(ShellStyles.SuccessStyle() + msg + ShellStyles.NormalStyle(), i==1) PlotHistograms(datasetsMgr, datasetsMgr_matched, h, intLumi) ROOT.gStyle.SetNdivisions(10, "X") Print("All plots saved under directory %s" % (ShellStyles.NoteStyle() + aux.convertToURL(opts.saveDir, opts.url) + ShellStyles.NormalStyle()), True) return
def main(opts): # Apply TDR style style = tdrstyle.TDRStyle() style.setOptStat(True) style.setGridX(True) style.setGridY(True) # Obtain dsetMgrCreator and register it to module selector dsetMgrCreator = dataset.readFromMulticrabCfg(directory=opts.mcrab) # Get list of eras, modes, and optimisation modes erasList = dsetMgrCreator.getDataEras() modesList = dsetMgrCreator.getSearchModes() optList = dsetMgrCreator.getOptimizationModes() sysVarList = dsetMgrCreator.getSystematicVariations() sysVarSrcList = dsetMgrCreator.getSystematicVariationSources() # If user does not define optimisation mode do all of them if opts.optMode == None: if len(optList) < 1: optList.append("") optModes = optList else: optModes = [opts.optMode] # For-loop: All opt Mode for opt in optModes: opts.optMode = opt # Setup & configure the dataset manager datasetsMgr = GetDatasetsFromDir(opts) datasetsMgr.updateNAllEventsToPUWeighted() datasetsMgr.loadLuminosities() # from lumi.json if opts.verbose: datasetsMgr.PrintCrossSections() datasetsMgr.PrintLuminosities() # Get the PSets: if 0: datasetsMgr.printSelections() #PrintPSet("BJetSelection", datasetsMgr, depth=150) # ZJets and DYJets overlap! if "ZJetsToQQ_HT600toInf" in datasetsMgr.getAllDatasetNames( ) and "DYJetsToQQ_HT180" in datasetsMgr.getAllDatasetNames(): Print( "Cannot use both ZJetsToQQ and DYJetsToQQ due to duplicate events? Investigate. Removing ZJetsToQQ datasets for now ..", True) datasetsMgr.remove( filter(lambda name: "ZJetsToQQ" in name, datasetsMgr.getAllDatasetNames())) # Merge histograms (see NtupleAnalysis/python/tools/plots.py) plots.mergeRenameReorderForDataMC(datasetsMgr) # Get luminosity if a value is not specified if opts.intLumi < 0: opts.intLumi = datasetsMgr.getDataset("Data").getLuminosity() # Remove datasets removeList = ["QCD-b"] #, "Charged"] if not opts.useMC: removeList.append("QCD") for i, d in enumerate(removeList, 0): msg = "Removing dataset %s" % d Verbose( ShellStyles.WarningLabel() + msg + ShellStyles.NormalStyle(), i == 0) datasetsMgr.remove( filter(lambda name: d in name, datasetsMgr.getAllDatasetNames())) # Print summary of datasets to be used if 0: datasetsMgr.PrintInfo() # Merge EWK samples datasetsMgr.merge("EWK", aux.GetListOfEwkDatasets()) # Print dataset information datasetsMgr.PrintInfo() # Do the fit on the histo after ALL selections (incl. topology cuts) folderList = datasetsMgr.getDataset( datasetsMgr.getAllDatasetNames()[0]).getDirectoryContent( opts.folder) #folderList1 = [h for h in folderList if "TetrajetPt" in h] #folderList1 = [h for h in folderList if "TetrajetMass" in h] #folderList1 = [h for h in folderList if "MET" in h] #folderList1 = [h for h in folderList if "TetrajetBJetPt" in h] folderList1 = [h for h in folderList if "QGLR" in h] folderList2 = [ h for h in folderList1 if "CRtwo" in h or "VR" in h or "SR" in h or "CRone" in h ] # For-loop: All folders histoPaths = [] for f in folderList2: folderPath = os.path.join(opts.folder, f) histoList = datasetsMgr.getDataset( datasetsMgr.getAllDatasetNames()[0]).getDirectoryContent( folderPath) pathList = [os.path.join(folderPath, h) for h in histoList] histoPaths.extend(pathList) binLabels = GetBinLabels("CRone", histoPaths) PlotHistosAndCalculateTF(datasetsMgr, histoPaths, binLabels, opts) return
def main(opts): # Apply TDR style style = tdrstyle.TDRStyle() style.setGridX(False) style.setGridY(False) style.setOptStat(False) # Obtain dsetMgrCreator and register it to module selector dsetMgrCreator = dataset.readFromMulticrabCfg(directory=opts.mcrab) # Get list of eras, modes, and optimisation modes erasList = dsetMgrCreator.getDataEras() modesList = dsetMgrCreator.getSearchModes() optList = dsetMgrCreator.getOptimizationModes() sysVarList = dsetMgrCreator.getSystematicVariations() sysVarSrcList = dsetMgrCreator.getSystematicVariationSources() # If user does not define optimisation mode do all of them if opts.optMode == None: optModes = optList else: optModes = [opts.optMode] # For-loop: All optimisation modes for opt in optModes: opts.optMode = opt # Setup & configure the dataset manager datasetsMgr = GetDatasetsFromDir(opts) datasetsMgr.updateNAllEventsToPUWeighted() datasetsMgr.loadLuminosities() # from lumi.json if 0: datasetsMgr.printSelections() # PrintPSet("BJetSelection", datasetsMgr) # PrintPSet("TopSelectionBDT", datasetsMgr) # PrintPSet("FakeBMeasurement", datasetsMgr) sys.exit() # Print dataset info? if opts.verbose: datasetsMgr.PrintCrossSections() datasetsMgr.PrintLuminosities() # Set signal cross-section if 0: datasetsMgr.getDataset(opts.signal).setCrossSection(1.0) # Remove unwanted datasets if 0: datasetsMgr.remove( filter(lambda name: "QCD-b" in name, datasetsMgr.getAllDatasetNames())) # Merge histograms (see NtupleAnalysis/python/tools/plots.py) plots.mergeRenameReorderForDataMC(datasetsMgr) # Get Luminosity opts.intLumi = datasetsMgr.getDataset("Data").getLuminosity() # Merge EWK samples datasetsMgr.merge("EWK", aux.GetListOfEwkDatasets()) plots._plotStyles["EWK"] = styles.getAltEWKStyle() # Print dataset information datasetsMgr.PrintInfo() # Get all the histograms and their paths (e.g. ForFakeBMeasurement/Baseline_DeltaRLdgTrijetBJetTetrajetBJet_AfterCRSelections) hList = datasetsMgr.getDataset( datasetsMgr.getAllDatasetNames()[0]).getDirectoryContent( opts.folder) hPaths = [os.path.join(opts.folder, h) for h in hList] # Create two lists of paths: one for "Baseline" (SR) and one for "Inverted" (CR) path_SR = [] # baseline, _AfterAllSelections path_CR1 = [] # baseline, _AfterCRSelections path_VR = [] # inverted, _AfterAllSelections path_CR2 = [] # inverted, _AfterCRSelections # For-loop: All histogram paths for p in hPaths: if "AfterStandardSelections" in p: #print p continue if "Baseline" in p: if "AllSelections" in p: path_SR.append(p) if "CRSelections" in p: path_CR1.append(p) if "Inverted" in p: if "AllSelections" in p: path_VR.append(p) if "CRSelections" in p: path_CR2.append(p) # For-loop: All histogram pairs for hVR, hCR2, hCR1 in zip(path_VR, path_CR2, path_CR1): break # not needed now if "IsGenuineB" in hVR: continue PlotComparison(datasetsMgr, hVR, hCR2, "VRvCR2") # For-loop: All histogram pairs counter = 1 for hCR1, hCR2 in zip(path_CR1, path_CR2): if "IsGenuineB" in hCR1: continue hName = hCR1.replace("_AfterCRSelections", "_CR1vCR2").replace( "ForFakeBMeasurement/Baseline_", "") msg = "{:<9} {:>3} {:<1} {:<3} {:<50}".format( "Histogram", "%i" % counter, "/", "%s:" % (len(path_CR1)), hName) Print(ShellStyles.SuccessStyle() + msg + ShellStyles.NormalStyle(), counter == 1) PlotComparison(datasetsMgr, hCR1, hCR2, "CR1vCR2") counter += 1 # For-loop: All histogram pairs for hSR, hVR in zip(path_SR, path_VR): break Print("UNBLINDING SR! Are you nuts ? BREAK!", False) if "IsGenuineB" in hSR: continue PlotComparison(datasetsMgr, hSR, hVR, "SRvVR") # # For-loop: All histogram pairs # for hSR, hCR1 in zip(path_SR, path_CR1): # #break # Print("UNBLINDING SR! Are you nuts ? BREAK!", False) # raw_input("Press any key to continue") # if "IsGenuineB" in hSR: # continue # PlotComparison(datasetsMgr, hSR, hCR1, "SRvCR1") Print( "All plots saved under directory %s" % (ShellStyles.NoteStyle() + aux.convertToURL(opts.saveDir, opts.url) + ShellStyles.NormalStyle()), True) return
def main(count, runRange, dsetList, opts): # Apply TDR style style = tdrstyle.TDRStyle() style.setOptStat(True) style.setGridX(True) style.setGridY(True) # Obtain dsetMgrCreator and register it to module selector dsetMgrCreator = dataset.readFromMulticrabCfg(directory=opts.mcrab) # Get list of eras, modes, and optimisation modes erasList = dsetMgrCreator.getDataEras() modesList = dsetMgrCreator.getSearchModes() optList = dsetMgrCreator.getOptimizationModes() sysVarList = dsetMgrCreator.getSystematicVariations() sysVarSrcList = dsetMgrCreator.getSystematicVariationSources() # If user does not define optimisation mode do all of them if opts.optMode == None: if len(optList) < 1: optList.append("") optModes = optList else: optModes = [opts.optMode] # For-loop: All opt Mode for opt in optModes: opts.optMode = opt # Setup & configure the dataset manager datasetsMgr = GetDatasetsFromDir(opts) datasetsMgr.updateNAllEventsToPUWeighted() datasetsMgr.loadLuminosities() # from lumi.json if opts.verbose: datasetsMgr.PrintCrossSections() datasetsMgr.PrintLuminosities() # Remove datasets removeList = ["QCD-b", "Charged", "QCD", "ZJetsToQQ_HT600toInf"] opts.intLumi = 0.0 # For-loop: All datasets in the manager for d in datasetsMgr.getAllDatasets(): if d.isMC(): continue # Inclusive data if len(dsetList) == 1 and dsetList[0] == "Run2016": Verbose("Inclusive data. Will not remove anything", True) opts.intLumi += GetLumi(datasetsMgr) break # Special combinations for rr in dsetList: if rr not in d.getName(): Verbose( "\"%s\" is not in dataset name \"%s\"" % (rr, d.getName()), False) if d.getName() not in removeList: # Ensure dataset to be removed is not in the dsetList if not any(rr in d.getName() for rr in dsetList): removeList.append(d.getName()) else: Verbose( "\"%s\" is in dataset name \"%s\"" % (rr, d.getName()), False) # Get luminosity if a value is not specified opts.intLumi += d.getLuminosity() # For-loop: All dataset names to be removed for i, d in enumerate(removeList, 0): Verbose( ShellStyles.HighlightAltStyle() + "Removing dataset %s" % d + ShellStyles.NormalStyle(), False) datasetsMgr.remove( filter(lambda name: d in name, datasetsMgr.getAllDatasetNames())) # Inform user of dataset and corresponding integrated lumi Print("%d) %s (%.1f 1/pb)" % (count, runRange, opts.intLumi), count == 1) #Print("%d) %s (%.1f 1/pb)" % (count, ", ".join(dsetList), opts.intLumi), count==1) # Merge histograms (see NtupleAnalysis/python/tools/plots.py) plots.mergeRenameReorderForDataMC(datasetsMgr) # Print dataset information if 0: datasetsMgr.PrintInfo() # Merge EWK samples datasetsMgr.merge("EWK", aux.GetListOfEwkDatasets()) # Do the fit on the histo after ALL selections (incl. topology cuts) folderList = datasetsMgr.getDataset( datasetsMgr.getAllDatasetNames()[0]).getDirectoryContent( opts.folder) folderList1 = [h for h in folderList if opts.histoKey in h] folderList2 = [ h for h in folderList1 if "VR" in h or "SR" in h or "CRone" in h or "CRtwo" in h or "CRthree" in h or "CRfour" in h ] # For-loop: All folders histoPaths = [] for f in folderList2: folderPath = os.path.join(opts.folder, f) histoList = datasetsMgr.getDataset( datasetsMgr.getAllDatasetNames()[0]).getDirectoryContent( folderPath) pathList = [os.path.join(folderPath, h) for h in histoList] histoPaths.extend(pathList) binLabels = GetBinLabels("CRone", histoPaths) PlotHistosAndCalculateTF(runRange, datasetsMgr, histoPaths, binLabels, opts) return
def main(opts): #optModes = ["", "OptChiSqrCutValue50", "OptChiSqrCutValue100"] optModes = [""] if opts.optMode != None: optModes = [opts.optMode] # For-loop: All opt Mode for opt in optModes: opts.optMode = opt # Setup & configure the dataset manager datasetsMgr = GetDatasetsFromDir(opts) datasetsMgr.updateNAllEventsToPUWeighted() datasetsMgr.loadLuminosities() # from lumi.json if 0: datasetsMgr.printSelections() sys.exit() # Define datasets to remove by default QCD_list = ["QCD_HT700to1000", "QCD_HT50to100", "QCD_HT500to700", "QCD_HT300to500", "QCD_HT200to300", "QCD_HT2000toInf", "QCD_HT1500to2000", "QCD_HT100to200", "QCD_HT1000to1500"] QCDExt_list = [x+"_ext1" for x in QCD_list] datasetsToRemove = ["QCD-b"] # datasetsToRemove.extend(QCD_list) # datasetsToRemove.extend(QCDExt_list) # ZJets and DYJets overlap if "ZJetsToQQ_HT600toInf" in datasetsMgr.getAllDatasetNames() and "DYJetsToQQ_HT180" in datasetsMgr.getAllDatasetNames(): Print("Cannot use both ZJetsToQQ and DYJetsToQQ due to duplicate events? Investigate. Removing ZJetsToQQ datasets for now ..", True) datasetsMgr.remove(filter(lambda name: "ZJetsToQQ" in name, datasetsMgr.getAllDatasetNames())) #datasetsMgr.remove(filter(lambda name: "DYJetsToQQ" in name, datasetsMgr.getAllDatasetNames())) # Set/Overwrite cross-sections for d in datasetsMgr.getAllDatasets(): if "ChargedHiggs" in d.getName(): datasetsMgr.getDataset(d.getName()).setCrossSection(1.0) # ATLAS 13 TeV H->tb exclusion limits if d.getName() != opts.signal: datasetsToRemove.append(d.getName()) if opts.verbose: datasetsMgr.PrintCrossSections() datasetsMgr.PrintLuminosities() # Merge histograms (see NtupleAnalysis/python/tools/plots.py) plots.mergeRenameReorderForDataMC(datasetsMgr) # Custom Filtering of datasets for i, d in enumerate(datasetsToRemove, 0): msg = "Removing dataset %s" % d Verbose(ShellStyles.WarningLabel() + msg + ShellStyles.NormalStyle(), i==0) datasetsMgr.remove(filter(lambda name: d == name, datasetsMgr.getAllDatasetNames())) if opts.verbose: datasetsMgr.PrintInfo() # Re-order datasets (different for inverted than default=baseline) newOrder = ["Data"] for i, d in enumerate(datasetsMgr.getAllDatasets(), 0): if d.isData(): continue else: newOrder.append(d.getName()) # Re-arrange dataset order? if 0: s = newOrder.pop( newOrder.index("noTop") ) newOrder.insert(len(newOrder), s) #after "Data" # Move signal to top if opts.signal in newOrder: s = newOrder.pop( newOrder.index(opts.signal) ) newOrder.insert(1, s) datasetsMgr.selectAndReorder(newOrder) # Merge EWK samples if opts.mergeEWK: datasetsMgr.merge("EWK", aux.GetListOfEwkDatasets()) plots._plotStyles["EWK"] = styles.getAltEWKStyle() # Print dataset information datasetsMgr.PrintInfo() # Apply TDR style style = tdrstyle.TDRStyle() style.setOptStat(True) style.setGridX(opts.gridX) style.setGridY(opts.gridY) # Do Data-MC histograms with DataDriven QCD folder = opts.folder histoList = datasetsMgr.getDataset(datasetsMgr.getAllDatasetNames()[0]).getDirectoryContent(folder) histoPaths = [os.path.join(folder, h) for h in histoList] ignoreList = ["Aplanarity", "Planarity", "Sphericity", "FoxWolframMoment", "Circularity", "ThirdJetResolution", "Centrality", "_Vs_"] myHistos = [] for h in histoPaths: skip = False # Skip unwanted histos for i in ignoreList: if i in h: skip = True if skip: continue else: myHistos.append(h) for i, h in enumerate(myHistos, 1): # Plot the histograms! msg = "{:<9} {:>3} {:<1} {:<3} {:<50}".format("Histogram", "%i" % i, "/", "%s:" % (len(myHistos)), h) Print(ShellStyles.SuccessStyle() + msg + ShellStyles.NormalStyle(), i==1) DataMCHistograms(datasetsMgr, h) Print("All plots saved under directory %s" % (ShellStyles.NoteStyle() + aux.convertToURL(opts.saveDir, opts.url) + ShellStyles.NormalStyle()), True) return
def main(opts): # Apply TDR style style = tdrstyle.TDRStyle() style.setGridX(False) style.setGridY(False) style.setOptStat(False) # Obtain dsetMgrCreator and register it to module selector dsetMgrCreator = dataset.readFromMulticrabCfg(directory=opts.mcrab) # Get list of eras, modes, and optimisation modes erasList = dsetMgrCreator.getDataEras() modesList = dsetMgrCreator.getSearchModes() optList = dsetMgrCreator.getOptimizationModes() sysVarList = dsetMgrCreator.getSystematicVariations() sysVarSrcList = dsetMgrCreator.getSystematicVariationSources() # If user does not define optimisation mode do all of them if opts.optMode == None: if len(optList) < 1: optList.append("") else: pass optModes = optList else: optModes = [opts.optMode] # For-loop: All optimisation modes for opt in optModes: opts.optMode = opt # Setup & configure the dataset manager datasetsMgr = GetDatasetsFromDir(opts) datasetsMgr.updateNAllEventsToPUWeighted() datasetsMgr.loadLuminosities() # from lumi.json if 0: datasetsMgr.printSelections() # Print PSets used for FakeBMeasurement if 0: datasetsMgr.printSelections() PrintPSet("BJetSelection", datasetsMgr) PrintPSet("TopSelectionBDT", datasetsMgr) PrintPSet("FakeBMeasurement", datasetsMgr) sys.exit() # Set/Overwrite cross-sections for d in datasetsMgr.getAllDatasets(): if "ChargedHiggs" in d.getName(): datasetsMgr.getDataset(d.getName()).setCrossSection(1.0) if opts.verbose: datasetsMgr.PrintCrossSections() datasetsMgr.PrintLuminosities() datasetsMgr.PrintInfo() # Filter the datasets datasetsMgr.remove(filter(lambda name: "Charged" in name, datasetsMgr.getAllDatasetNames())) # datasetsMgr.remove(filter(lambda name: "Charged" in name and not "M_500" in name, datasetsMgr.getAllDatasetNames())) # ZJets and DYJets overlap! if "ZJetsToQQ_HT600toInf" in datasetsMgr.getAllDatasetNames() and "DYJetsToQQ_HT180" in datasetsMgr.getAllDatasetNames(): Print("Cannot use both ZJetsToQQ and DYJetsToQQ due to duplicate events? Investigate. Removing ZJetsToQQ datasets for now ..", True) datasetsMgr.remove(filter(lambda name: "ZJetsToQQ" in name, datasetsMgr.getAllDatasetNames())) # Merge histograms (see NtupleAnalysis/python/tools/plots.py) plots.mergeRenameReorderForDataMC(datasetsMgr) # Get Luminosity if opts.intLumi < 0: if "Data" in datasetsMgr.getAllDatasetNames(): opts.intLumi = datasetsMgr.getDataset("Data").getLuminosity() else: opts.intLumi = 1.0 # Re-order datasets (different for inverted than default=baseline) if 0: newOrder = ["Data"] newOrder.extend(aux.GetListOfEwkDatasets()) datasetsMgr.selectAndReorder(newOrder) # Print post-merged data dataset summary if 0: datasetsMgr.PrintInfo() # Merge EWK samples datasetsMgr.merge("EWK", aux.GetListOfEwkDatasets()) plots._plotStyles["EWK"] = styles.getAltEWKStyle() # Print post EWK-merge dataset summary if 1: datasetsMgr.PrintInfo() # Get all histograms from the in the selected folder inside the ROOT files allHistos = datasetsMgr.getAllDatasets()[0].getDirectoryContent(opts.folder) hList = [h for h in allHistos if "CRSelections" in h and "_Vs" not in h] hList.extend([h for h in allHistos if "AllSelections" in h and "_Vs" not in h]) # hList.extend([h for h in allHistos if "StandardSelections" in h and "_Vs" not in h]) # Create a list with strings included in the histogram names you want to plot myHistos = ["LdgTrijetPt", "LdgTrijetMass", "TetrajetBJetPt", "TetrajetBJetEta", "LdgTetrajetPt", "LdgTetrajetMass", "MVAmax2", "MVAmax1", "HT", "MET"] # For-loop: All histos for i, h in enumerate(myHistos, 1): hGraphList = [] for b in ["Baseline_", "Inverted_"]: for r in [ "_AfterCRSelections", "_AfterAllSelections"]: histoName = b + h + r hgQCD, kwargs = GetPurityHistoGraph(datasetsMgr, opts.folder, histoName) # Do not draw SR in multigraph plot! if GetControlRegionLabel(histoName) != "SR": hGraphList.append(hgQCD) # Plot individual purity graphs? if 0: PlotHistoGraph(hgQCD, kwargs) msg = "{:<9} {:>3} {:<1} {:<3} {:<50}".format("Histogram", "%i" % i, "/", "%s:" % (len(myHistos)), h) Print(ShellStyles.SuccessStyle() + msg + ShellStyles.NormalStyle(), i==1) PlotHistoGraphs(hGraphList, kwargs) Print("All plots saved under directory %s" % (ShellStyles.NoteStyle() + aux.convertToURL(opts.saveDir, opts.url) + ShellStyles.NormalStyle()), True) return
def main(opts): optModes = [""] if opts.optMode != None: optModes = [opts.optMode] # Apply TDR style style = tdrstyle.TDRStyle() style.setOptStat(False) style.setGridX(opts.gridX) style.setGridY(opts.gridY) style.setLogX(opts.logX) style.setLogY(opts.logY) style.setLogZ(opts.logZ) # For-loop: All opt Mode for opt in optModes: opts.optMode = opt # Setup & configure the dataset manager datasetsMgr = GetDatasetsFromDir(opts) datasetsMgr.updateNAllEventsToPUWeighted() datasetsMgr.loadLuminosities() # from lumi.json if opts.verbose: datasetsMgr.PrintCrossSections() datasetsMgr.PrintLuminosities() datasetsMgr.PrintInfo() # Merge histograms (see NtupleAnalysis/python/tools/plots.py) plots.mergeRenameReorderForDataMC(datasetsMgr) # Print merged datasets and MC samples if 0: datasetsMgr.PrintInfo() # Get Luminosity if opts.intLumi < 0: if "Data" in datasetsMgr.getAllDatasetNames(): opts.intLumi = datasetsMgr.getDataset("Data").getLuminosity() else: opts.intLumi = 1.0 # Set/Overwrite cross-sections. Remove all but 1 signal mass removeList = [] for d in datasetsMgr.getAllDatasets(): if "ChargedHiggs" in d.getName(): datasetsMgr.getDataset(d.getName()).setCrossSection(1.0) if d.getName() != opts.signal: removeList.append(d.getName()) # Custom filtering of datasets for i, d in enumerate(removeList, 1): msg = "Removing datasets %s from dataset manager" % ( ShellStyles.NoteStyle() + d + ShellStyles.NormalStyle()) Verbose(msg, i == 1) datasetsMgr.remove( filter(lambda name: d == name, datasetsMgr.getAllDatasetNames())) # Merge EWK samples if opts.mergeEWK == "EWK": datasetsMgr.merge("EWK", aux.GetListOfEwkDatasets()) plots._plotStyles["EWK"] = styles.getAltEWKStyle() # Print dataset information if 1: datasetsMgr.PrintInfo() # Get list of histogram paths folder = opts.folder histoList = datasetsMgr.getDataset( datasetsMgr.getAllDatasetNames()[0]).getDirectoryContent(folder) histoPaths = [os.path.join(folder, h) for h in histoList] # For-loop: All histograms for i, h in enumerate(histoPaths, 1): if "_Vs_" in h: continue msg = "{:<9} {:>3} {:<1} {:<3} {:<50}".format( "Histogram", "%i" % i, "/", "%s:" % (len(histoPaths)), h) Print(ShellStyles.SuccessStyle() + msg + ShellStyles.NormalStyle(), i == 1) PlotHistograms(datasetsMgr, h) break Print( "All plots saved under directory %s" % (ShellStyles.NoteStyle() + aux.convertToURL(opts.saveDir, opts.url) + ShellStyles.NormalStyle()), True) return
def main(opts): optModes = [""] if opts.optMode != None: optModes = [opts.optMode] # Apply TDR style style = tdrstyle.TDRStyle() style.setOptStat(False) style.setGridX(opts.gridX) style.setGridY(opts.gridY) style.setLogX(opts.logX) style.setLogY(opts.logY) style.setLogZ(opts.logZ) style.setWide(True, 0.15) # style.setPadRightMargin()#0.13) # For-loop: All opt Mode for opt in optModes: opts.optMode = opt # Setup & configure the dataset manager datasetsMgr = GetDatasetsFromDir(opts) datasetsMgr.updateNAllEventsToPUWeighted() datasetsMgr.loadLuminosities() # from lumi.json if opts.verbose: datasetsMgr.PrintCrossSections() datasetsMgr.PrintLuminosities() datasetsMgr.PrintInfo() # Merge histograms (see NtupleAnalysis/python/tools/plots.py) plots.mergeRenameReorderForDataMC(datasetsMgr) # Print merged datasets and MC samples if 0: datasetsMgr.PrintInfo() # Get Luminosity if opts.intLumi < 0: opts.intLumi = datasetsMgr.getDataset("Data").getLuminosity() # Merge EWK samples if opts.dataset == "EWK": datasetsMgr.merge("EWK", aux.GetListOfEwkDatasets()) plots._plotStyles["EWK"] = styles.getAltEWKStyle() # Re-order datasets (different for inverted than default=baseline) newOrder = [] for d in datasetsMgr.getAllDatasets(): if d.getName() == opts.dataset: newOrder.append(d.getName()) # Sanity check on selected dataset nDatasets = len(newOrder) if nDatasets < 1: msg = "Please select a valid dataset. Dataset \"%s\" does not exist!" % ( opts.dataset) Print(ShellStyles.ErrorStyle() + msg + ShellStyles.NormalStyle(), True) datasetsMgr.PrintInfo() sys.exit() if nDatasets > 1: msg = "Please select only 1 valid dataset. Requested %i datasets for plotting!" % ( nDatasets) Print(ShellStyles.ErrorStyle() + msg + ShellStyles.NormalStyle(), True) datasetsMgr.PrintInfo() sys.exit() # Select only given dataset datasetsMgr.selectAndReorder(newOrder) # Print dataset information msg = "Plotting for single dataset \"%s\". Integrated luminosity is %.2f 1/fb" % ( opts.dataset, opts.intLumi) Print(ShellStyles.NoteStyle() + msg + ShellStyles.NormalStyle(), True) datasetsMgr.PrintInfo() # Get list of histogram paths folder = opts.folder histoList = datasetsMgr.getDataset( datasetsMgr.getAllDatasetNames()[0]).getDirectoryContent(folder) histoPaths = [os.path.join(folder, h) for h in histoList] # For-loop: All histograms for h in histoPaths: if "_vs_" not in h.lower(): continue Plot2dHistograms(datasetsMgr, h) Print( "All plots saved under directory %s" % (ShellStyles.NoteStyle() + aux.convertToURL(opts.saveDir, opts.url) + ShellStyles.NormalStyle()), True) return
def main(opts): optModes = [""] if opts.optMode != None: optModes = [opts.optMode] # Apply TDR style global style style = tdrstyle.TDRStyle() style.setOptStat(False) style.setGridX(opts.gridX) style.setGridY(opts.gridY) style.setLogX(opts.logX) style.setLogY(opts.logY) # For-loop: All opt Mode for opt in optModes: opts.optMode = opt # Setup & configure the dataset manager datasetsMgr = GetDatasetsFromDir(opts) datasetsMgr.updateNAllEventsToPUWeighted() datasetsMgr.loadLuminosities() # from lumi.json if opts.verbose: datasetsMgr.PrintCrossSections() datasetsMgr.PrintLuminosities() datasetsMgr.PrintInfo() # Merge histograms (see NtupleAnalysis/python/tools/plots.py) plots.mergeRenameReorderForDataMC(datasetsMgr) # Print merged datasets and MC samples if 0: datasetsMgr.PrintInfo() # Get Luminosity if opts.intLumi == 0.0: if "Data" in datasetsMgr.getAllDatasetNames(): opts.intLumi = datasetsMgr.getDataset("Data").getLuminosity() else: opts.intLumi = GetLumi(datasetsMgr) # Set/Overwrite cross-sections. Remove all but 1 signal mass signalsList = [] for s in opts.signalList: signalsList.append("ChargedHiggs_HplusTB_HplusToTB_M_%s" % s) # Remove datasets with overlap? removeList = ["QCD-b"] dsetDY = "DYJetsToQQ_HT180" dsetZJ = "ZJetsToQQ_HT600toInf" dsetRM = dsetZJ # datasets with overlap removeList.append(dsetRM) for d in datasetsMgr.getAllDatasets(): if "ChargedHiggs" in d.getName(): datasetsMgr.getDataset(d.getName()).setCrossSection(1.0) if d.getName() not in signalsList: removeList.append(d.getName()) # Custom filtering of datasets for i, d in enumerate(removeList, 1): msg = "Removing datasets %s from dataset manager" % (ShellStyles.NoteStyle() + d + ShellStyles.NormalStyle()) Verbose(msg, i==1) datasetsMgr.remove(filter(lambda name: d == name, datasetsMgr.getAllDatasetNames())) # Merge EWK samples if opts.mergeEWK == "EWK": datasetsMgr.merge("EWK", aux.GetListOfEwkDatasets()) plots._plotStyles["EWK"] = styles.getAltEWKStyle() # Print dataset information if 1: datasetsMgr.PrintInfo() # Get list of histogram paths folder = opts.folder histoList = datasetsMgr.getDataset(datasetsMgr.getAllDatasetNames()[0]).getDirectoryContent(folder) histoPaths = [os.path.join(folder, h) for h in histoList if "AllSelections" in h] myHistos = [] skipStrings = ["StandardSelections", "JetPt", "JetEta", "JetEtaPhi", "BJetPt", "BJetEta", "BtagDiscriminator", "Eta", "LdgTrijetTopMassWMassRatio", "Subldg", "Dijet", "MET", "MHT", "MinDeltaPhiJetMHT", "MaxDeltaPhiJetMHT", "MinDeltaRJetMHT", "MinDeltaRJetMHTReversed"] for h in histoPaths: bSkip = False for s in skipStrings: if s in h: bSkip = True break if bSkip: continue else: myHistos.append(h) # For-loop: All histograms for i, h in enumerate(myHistos, 1): msg = "{:<9} {:>3} {:<1} {:<3} {:<50}".format("Histogram", "%i" % i, "/", "%s:" % (len(myHistos)), h) Print(ShellStyles.SuccessStyle() + msg + ShellStyles.NormalStyle(), i==1) PlotHistograms(datasetsMgr, h, signalsList, opts.cutDir) Print("All plots saved under directory %s" % (ShellStyles.NoteStyle() + aux.convertToURL(opts.saveDir, opts.url) + ShellStyles.NormalStyle()), True) return