def getMainCounterTable(emb, sig): ec = counter.EventCounter(emb) ec2 = counter.EventCounter(sig) colName = "Data" if not useData: ec.normalizeMCByLuminosity() ec2.normalizeMCByLuminosity() colName = "MC" table = counter.CounterTable() col = ec.getMainCounterTable().getColumn(name=colName) col.setName("Embedded") table.appendColumn(col) col = col.copy() col.setName("Embedded (norm)") col.multiply(embeddingNormalisation.value(), embeddingNormalisation.uncertainty()) table.appendColumn(col) col = ec2.getMainCounterTable().getColumn(name=colName) col.setName("Normal") table.appendColumn(col) return table
def doCounters(datasets): # Create EventCounter object, holds all counters of all datasets eventCounter = counter.EventCounter(datasets) # Normalize counters if mcOnly: eventCounter.normalizeMCToLuminosity(mcOnlyLumi) else: eventCounter.normalizeMCByLuminosity() # Get table (counter.CounterTable) of the main counter, format it # with default formatting, and print #print eventCounter.getMainCounterTable().format() # Create LaTeX format, automatically adjust value precision by uncertainty latexFormat = counter.TableFormatLaTeX( counter.CellFormatTeX(valueFormat="%.4f", withPrecision=2)) # Get table of a subcounter, format it with a predefined format, # and print #print eventCounter.getSubCounterTable("TauIDPassedEvt::TauSelection_HPS").format(latexFormat) # Create EventCounter from one dataset eventCounter = counter.EventCounter(datasets.getAllDatasets()[0]) if mcOnly: eventCounter.normalizeMCToLuminosity(mcOnlyLumi) else: eventCounter.normalizeMCByLuminosity()
def printCounters(datasets, selectionName, ntupleCache, selectorName, onlyDataset=None): global printed if not printed: print "============================================================" print "Dataset info: " datasets.printInfo() printed = True if not doWeighted: eventCounter = counter.EventCounter(datasets, counters=counters) counterPath = "counters/counter" else: eventCounter = counter.EventCounter(datasets) counterPath = "counters/weighted/counter" if onlyDataset != None: eventCounter.removeColumns( filter(lambda n: n != onlyDataset, datasets.getAllDatasetNames())) eventCounter.getMainCounter().appendRows( ntupleCache.histogram(counterPath, selectorName)) if mergeMC: if mcOnly: eventCounter.normalizeMCToLuminosity(mcLuminosity) else: eventCounter.normalizeMCByLuminosity() table = eventCounter.getMainCounterTable() mcDatasets = filter(lambda n: n != "Data", table.getColumnNames()) if len(mcDatasets) != 0: col = 1 if mcOnly: col = 0 table.insertColumn( col, counter.sumColumn( "MCSum", [table.getColumn(name=name) for name in mcDatasets])) cellFormat = counter.TableFormatText( counter.CellFormatText(valueFormat='%.3f')) # cellFormat = counter.TableFormatText(counter.CellFormatTeX(valueFormat='%.1f')) output = table.format(cellFormat) print print "########################################" print "Selection", selectionName print output prefix = era + "_" + selectionName + "_counters" if not doWeighted: prefix += "_nonweighted" f = open(prefix + ".txt", "w") f.write(output) f.close()
def validateCounters(dataset1, dataset2): eventCounter1 = counter.EventCounter(dataset1) counter1 = eventCounter1.getMainCounter().getTable() rownames1 = counter1.getRowNames() eventCounter2 = counter.EventCounter(dataset2) counter2 = eventCounter2.getMainCounter().getTable() rownames2 = counter2.getRowNames() rownames = validateNames(rownames1, rownames2) myoutput = validateCounterValues(rownames, counter1, counter2) return myoutput
def doCounters(muonDatasets, tauDatasets, datasetName): ecMuon = counter.EventCounter(muonDatasets) ecMuonWeighted = counter.EventCounter(muonDatasets, counters="counters/weighted") ecTau = counter.EventCounter(tauDatasets) def isNotThis(name): return name != datasetName ecMuon.removeColumns(filter(isNotThis, muonDatasets.getAllDatasetNames())) ecMuonWeighted.removeColumns( filter(isNotThis, muonDatasets.getAllDatasetNames())) ecTau.removeColumns(filter(isNotThis, tauDatasets.getAllDatasetNames())) ecMuon.normalizeMCToLuminosity(mcLumi) ecMuonWeighted.normalizeMCToLuminosity(mcLumi) ecTau.normalizeMCToLuminosity(mcLumi) table = counter.CounterTable() col = ecMuon.getMainCounterTable().getColumn(name=datasetName) col.setName("Muon") col.setCount( -1, ecMuonWeighted.getMainCounterTable().getCount(irow=-1, colName=datasetName)) muonEvents = col.getCount(name="= 1 gen muon").clone() muonEventsWeighted = col.getCount(-1).clone() table.appendColumn(col) col = ecTau.getMainCounterTable().getColumn(name=datasetName) col.setName("Tau") tauEvents = col.getCount(-1).clone() table.appendColumn(col) print table.format() ratio = tauEvents.clone() ratio.divide(muonEvents) ratioWeighted = tauEvents.clone() ratioWeighted.divide(muonEventsWeighted) print "Tau/Muon = %f +- %f" % (ratio.value(), ratio.uncertainty()) print "Tau/Muon(ID) = %f +- %f" % (ratioWeighted.value(), ratioWeighted.uncertainty()) print ratio = muonEvents.clone() ratio.divide(tauEvents) ratioWeighted = muonEventsWeighted.clone() ratioWeighted.divide(tauEvents) print "Muon/Tau = %f +- %f" % (ratio.value(), ratio.uncertainty()) print "Muon(ID)/Tau = %f +- %f" % (ratioWeighted.value(), ratioWeighted.uncertainty())
def validateCounters(dataset1, dataset2): eventCounter1 = counter.EventCounter(dataset1) counter1 = eventCounter1.getMainCounter().getTable() rownames1 = counter1.getRowNames() eventCounter2 = counter.EventCounter(dataset2) counter2 = eventCounter2.getMainCounter().getTable() rownames2 = counter2.getRowNames() rownames = validateNames(rownames1, rownames2) discrepancyFound = validateCounterValues(rownames, counter1, counter2) if not discrepancyFound: print " Validated OK"
def doCounters(muonDatasets, tauDatasets, datasetName, ntupleCacheMuon, ntupleCacheTau): ecMuon = counter.EventCounter(muonDatasets) #ecMuonWeighted = counter.EventCounter(muonDatasets, counters="counters/weighted") ecTau = counter.EventCounter(tauDatasets) def isNotThis(name): return name != datasetName ecMuon.removeColumns(filter(isNotThis, muonDatasets.getAllDatasetNames())) #ecMuonWeighted.removeColumns(filter(isNotThis, muonDatasets.getAllDatasetNames())) ecTau.removeColumns(filter(isNotThis, tauDatasets.getAllDatasetNames())) ecMuon.normalizeMCToLuminosity(mcLumi) #ecMuonWeighted.normalizeMCToLuminosity(mcLumi) ecTau.normalizeMCToLuminosity(mcLumi) ecMuon.getMainCounter().appendRows( ntupleCacheMuon.histogram("counters/weighted/counter")) ecTau.getMainCounter().appendRows( ntupleCacheTau.histogram("counters/weighted/counter")) table = counter.CounterTable() muonCol = ecMuon.getMainCounterTable().getColumn(name=datasetName) muonCol.setName("Muon") #col.setCount(-1, ecMuonWeighted.getMainCounterTable().getCount(irow=-1, colName=datasetName)) table.appendColumn(muonCol) tauCol = ecTau.getMainCounterTable().getColumn(name=datasetName) tauCol.setName("Tau") table.appendColumn(tauCol) print table.format() def printRatio(muonCount, tauCount): ratio1 = tauCol.getCount(name=tauCount).clone() ratio1.divide(muonCol.getCount(name=muonCount)) ratio2 = muonCol.getCount(name=muonCount).clone() ratio2.divide(tauCol.getCount(name=tauCount)) print "Tau/Muon = %f +- %f, Muon/Tau = %f +- %f" % ( ratio1.value(), ratio1.uncertainty(), ratio2.value(), ratio2.uncertainty()) print "Generator level" printRatio("= 1 gen muon", "= 1 gen tau") print print "Reco muon vs. gen tau, after muon veto" printRatio("muon id eff weighting", "reco muon veto")
def printCounters(datasets): print "============================================================" print "Dataset info: " datasets.printInfo() eventCounter = counter.EventCounter(datasets) if True: selection = "Sum$(%s) >= 1" % muonKinematics eventCounter.getMainCounter().appendRow("Muon kinematics", treeDraw.clone(selection=selection)) selection = "Sum$(%s && %s) >= 1" % (muonKinematics, muondB) eventCounter.getMainCounter().appendRow("Muon IP", treeDraw.clone(selection=selection)) selection = "Sum$(%s && %s && %s) >= 1" % (muonKinematics, muondB, muonIsolation) eventCounter.getMainCounter().appendRow("Muon isolation", treeDraw.clone(selection=selection)) selection = "Sum$(%s && %s && %s) == 1" % (muonKinematics, muondB, muonIsolation) print selection eventCounter.getMainCounter().appendRow("One selected muon", treeDraw.clone(selection=selection)) selection += "&&" +muonVeto print selection eventCounter.getMainCounter().appendRow("Muon veto", treeDraw.clone(selection=selection)) selection += "&&" +electronVeto print selection eventCounter.getMainCounter().appendRow("Electron veto", treeDraw.clone(selection=selection)) selection += "&&" +jetSelection print selection eventCounter.getMainCounter().appendRow("Jet selection", treeDraw.clone(selection=selection)) eventCounter.normalizeMCByLuminosity() table = eventCounter.getMainCounterTable() addSumColumn(table) cellFormat = counter.TableFormatText(counter.CellFormatText(valueFormat='%.3f')) print table.format(cellFormat)
def doCounters(opts, dsetMgr, moduleInfoString, myDir, luminosity, normFactors): def printSubCounterTable(eventCounter, subCounterName, cellFormat): # Check existence if subCounterName in eventCounter.getSubCounterNames(): # Subcounter exists, go ahead and print it return eventCounter.getSubCounterTable(subCounterName).format( cellFormat) else: return "Subcounter '%s' does not exist (please note that for optimization runs subcounters are not saved)" % subCounterName eventCounter = counter.EventCounter(dsetMgr) eventCounter.normalizeMCToLuminosity(myLuminosity) print "============================================================" print "Main counter (MC normalized by collision data luminosity)" mainTable = eventCounter.getMainCounterTable() # No uncertainties cellFormat = counter.TableFormatText(cellFormat=counter.CellFormatText( valueOnly=True)) myOutput = "" myOutput += mainTable.format(cellFormat) + "\n\n" myOutput += printSubCounterTable(eventCounter, "b-tagging", cellFormat) + "\n\n" myOutput += printSubCounterTable(eventCounter, "Jet selection", cellFormat) + "\n\n" myOutput += printSubCounterTable(eventCounter, "Jet main", cellFormat) + "\n\n" # Write the output to file f = open(os.path.join(myDir, "counterOutput.txt"), "w") f.write(myOutput) f.close() # Write the output to screen print myOutput
def doCounters(datasetsEmb, datasetsSig, datasetName): lumi = datasetsEmb.getLuminosity() # Counters eventCounterEmb = tauEmbedding.EventCounterMany(datasetsEmb) eventCounterSig = counter.EventCounter(datasetsSig) def isNotThis(name): return name != datasetName eventCounterEmb.removeColumns(filter(isNotThis, datasetsEmb.getAllDatasetNames())) eventCounterSig.removeColumns(filter(isNotThis, datasetsSig.getAllDatasetNames())) eventCounterSig.normalizeMCToLuminosity(lumi) tableEmb = eventCounterEmb.getMainCounterTable() tableSig = eventCounterSig.getMainCounterTable() table = counter.CounterTable() col = tableEmb.getColumn(name=datasetName) col.setName(datasetName+" emb") table.appendColumn(col) col = tableSig.getColumn(name=datasetName) col.setName(datasetName+" norm") table.appendColumn(col) table.keepOnlyRows([ "njets", "MET", "btagging", "btagging scale factor", "deltaPhiTauMET<160", "deltaPhiTauMET<130", ]) table.renameRows({"njets": "tau ID"}) return table
def doCounters(datasetsEmb, outputDir): eventCounter = counter.EventCounter(datasetsEmb) eventCounter.normalizeMCToLuminosity( datasetsEmb.getDataset("Data").getLuminosity()) table = eventCounter.getMainCounterTable() table.keepOnlyRows([ "Trigger and HLT_MET cut", "taus > 0", "tau trigger scale factor", "electron veto", "muon veto", "njets", "MET trigger scale factor", "QCD tail killer collinear", "MET", "btagging", "btagging scale factor", "Embedding: mT weight", "QCD tail killer back-to-back", "Selected events" ]) addMcSum(table) cellFormat = counter.TableFormatText( counter.CellFormatTeX(valueFormat='%.4f', withPrecision=2)) txt = table.format(cellFormat) print txt d = outputDir if d is None: d = "." if not os.path.exists(d): os.makedirs(d) f = open(os.path.join(d, "counters.txt"), "w") f.write(txt) f.write("\n")
def doCounters(datasets): eventCounter = counter.EventCounter(datasets, counters=analysisEmb + counters) if not mcEvents: if onlyWjets: eventCounter.normalizeMCToLuminosity(lumi) else: eventCounter.normalizeMCByLuminosity() tauEmbedding.scaleNormalization(eventCounter) mainTable = eventCounter.getMainCounterTable() ewkDatasets = ["WJets", "TTJets", "DYJetsToLL", "SingleTop", "Diboson"] def ewkSum(table): table.insertColumn( 1, counter.sumColumn( "EWKMCsum", [table.getColumn(name=name) for name in ewkDatasets])) if not onlyWjets and not mcEvents: ewkSum(mainTable) return mainTable.getRow(name="deltaPhiTauMET<160")
def makeEventCounter(ds): modifyCountNames = PrefixModify() for d in ds.getAllDatasets(): prefix = d.getPrefix() if prefix != "": modifyCountNames.addPrefix(prefix) return counter.EventCounter(ds, modifyCountNames)
def doCounters(datasets): eventCounter = counter.EventCounter(datasets) # append row from the tree to the main counter eventCounter.getMainCounter().appendRow( "MET > 70", treeDraw.clone(selection="met_p4.Et() > 70")) ewkDatasets = ["WJets", "TTJets", "DYJetsToLL", "SingleTop", "Diboson"] eventCounter.normalizeMCByLuminosity() # eventCounter.normalizeMCToLuminosity(73) print "============================================================" print "Main counter (MC normalized by collision data luminosity)" mainTable = eventCounter.getMainCounterTable() mainTable.insertColumn( 2, counter.sumColumn( "EWKMCsum", [mainTable.getColumn(name=name) for name in ewkDatasets])) print mainTable.format() # print eventCounter.getSubCounterTable("GlobalMuon_ID").format() print eventCounter.getSubCounterTable("tauIDTauSelection").format() print eventCounter.getSubCounterTable( "TauIDPassedEvt::tauID_HPSTight").format() # print eventCounter.getSubCounterTable("TauIDPassedJets::tauID_HPSTight").format() print eventCounter.getSubCounterTable("b-tagging").format() print eventCounter.getSubCounterTable("Jet selection").format() print eventCounter.getSubCounterTable("Jet main").format()
def main(): # Read the datasets datasets = dataset.getDatasetsFromMulticrabCfg(counters=counters) datasets.updateNAllEventsToPUWeighted() #datasets.loadLuminosities() plots.mergeRenameReorderForDataMC(datasets) # Set the signal cross sections to a given BR(t->H), BR(h->taunu) xsect.setHplusCrossSectionsToBR(datasets, br_tH=0.05, br_Htaunu=1) # Set the signal cross sections to a value from MSSM # xsect.setHplusCrossSectionsToMSSM(datasets, tanbeta=20, mu=200) plots.mergeWHandHH( datasets ) # merging of WH and HH signals must be done after setting the cross section # Create counter eventCounter = counter.EventCounter(datasets) #eventCounter.normalizeMCByLuminosity() eventCounter.normalizeMCToLuminosity(1000) # in pb^-1 print "============================================================" print "Main counter (MC normalized by collision data luminosity)" print eventCounter.getMainCounterTable().format() triggerCounter = eventCounter.getSubCounter("Trigger") triggerCounter.forEachDataset(printTriggerEfficiency)
def __init__(self, datasetsMany, scaleNormalization=True, *args, **kwargs): self.eventCounters = [] for dsMgr in datasetsMany.datasetManagers: ec = counter.EventCounter(dsMgr, *args, **kwargs) ec.normalizeMCToLuminosity(datasetsMany.getLuminosity()) if scaleNormalization: tauEmbedding.scaleNormalization(ec) self.eventCounters.append(ec)
def getMainCounterTable(self, dataset): table = counter.CounterTable() for an, dm in zip(self.analyses, self.datasetManagers): eventCounter = counter.EventCounter(dm) eventCounter.normalizeMCByLuminosity() tmpTable = eventCounter.getMainCounterTable() col = tmpTable.getColumn(name=dataset) col.setName(legends[an]) table.appendColumn(col) return table
def __init__(self, datasetsDYCorrection, counters=None, **kwargs): self.datasetsDYCorrection = datasetsDYCorrection countersSig = counters if countersSig != None: countersSig = datasetsDYCorrection._replaceSigName(countersSig) self.eventCounterEmb = EventCounterMany( datasetsDYCorrection.datasetsEmb, counters=counters, **kwargs) self.eventCounterSig = counter.EventCounter( datasetsDYCorrection.datasetsSig, counters=countersSig, **kwargs) self.eventCounterSig.normalizeMCToLuminosity( datasetsDYCorrection.datasetsEmb.getLuminosity())
def doCounters(myDsetMgr, mySuffix, isSystematicVariation): eventCounter = counter.EventCounter(myDsetMgr) # append row from the tree to the main counter # eventCounter.getMainCounter().appendRow("MET > 70", treeDraw.clone(selection="met_p4.Et() > 70")) ewkDatasets = [ "WJets", "TTJets", "DYJetsToLL", "SingleTop", "Diboson" ] if myDsetMgr.hasDataset("W1Jets"): ewkDatasets.extend(["W1Jets", "W2Jets", "W3Jets", "W4Jets"]) if mcOnly: eventCounter.normalizeMCToLuminosity(mcOnlyLumi) else: eventCounter.normalizeMCByLuminosity() print "============================================================" print mySuffix print "============================================================" out = open(os.path.join(mySuffix, "counters.txt"), "w") def printAndSave(line): print line out.write(line) out.write("\n") printAndSave("Main counter (MC normalized by collision data luminosity)") mainTable = eventCounter.getMainCounterTable() mainTable.insertColumn(2, counter.sumColumn("EWKMCsum", [mainTable.getColumn(name=name) for name in ewkDatasets])) # Default # cellFormat = counter.TableFormatText() # No uncertainties cellFormat = counter.TableFormatText(cellFormat=counter.CellFormatText(valueOnly=False)) printAndSave(mainTable.format(cellFormat)) if not isSystematicVariation: # printAndSave(eventCounter.getSubCounterTable("tauIDTauSelection").format()) printAndSave(eventCounter.getSubCounterTable("TauIDPassedEvt::TauSelection_HPS").format(cellFormat)) printAndSave(eventCounter.getSubCounterTable("TauIDPassedJets::TauSelection_HPS").format(cellFormat)) printAndSave(eventCounter.getSubCounterTable("b-tagging").format(cellFormat)) printAndSave(eventCounter.getSubCounterTable("Jet selection").format(cellFormat)) printAndSave(eventCounter.getSubCounterTable("Jet main").format(cellFormat)) printAndSave(eventCounter.getSubCounterTable("VetoTauSelection").format(cellFormat)) printAndSave(eventCounter.getSubCounterTable("MuonSelection").format(cellFormat)) printAndSave(eventCounter.getSubCounterTable("MCinfo for selected events").format(cellFormat)) printAndSave(eventCounter.getSubCounterTable("ElectronSelection").format(cellFormat)) # printAndSave(eventCounter.getSubCounterTable("top").format(cellFormat)) out.close()
def doCounters(datasetsEmb, datasetsSig): rows = [ "njets", "MET", "btagging scale factor", "deltaPhiTauMET<160", "deltaPhiTauMET<130" ] residuals = ["DYJetsToLL residual", "WW residual"] # Normal MC eventCounterNormal = counter.EventCounter(datasetsSig) eventCounterNormal.normalizeMCToLuminosity(datasetsEmb.getLuminosity()) tableNormal = eventCounterNormal.getMainCounterTable() tableNormal.keepOnlyRows(rows) # Embedded data and MC, residual MC eventCounter = tauEmbedding.EventCounterResidual(datasetsEmb) table = eventCounter.getMainCounterTable() table.keepOnlyRows(rows) # Build the result result = counter.CounterTable() c = table.getColumn(name="Data") c.setName("Embedded data") result.appendColumn(c) #result.appendColumn(table.getColumn(name="EWKMC")) for name in residuals: result.appendColumn(table.getColumn(name=name)) result.appendColumn( counter.sumColumn( "Emb. data + res. MC", [table.getColumn(name=name) for name in ["Data"] + residuals])) result.appendColumn( counter.sumColumn( "Emb. MC + res. MC", [table.getColumn(name=name) for name in ["EWKMC"] + residuals])) c = tableNormal.getColumn(name="EWKMC") c.setName("Normal MC") result.appendColumn(c) # Final formatting result.renameRows({ "njets": "tau-jet identification", "btagging scale factor": "b tagging" }) cellFormat = counter.TableFormatLaTeX( counter.CellFormatTeX(valueFormat='%.4f', withPrecision=2)) print result.format(cellFormat)
def __init__(self, datasetsResidual, counters=None, **kwargs): self.datasetsResidual = datasetsResidual self.residualNames = datasetsResidual.residualNames countersSig = counters if countersSig != None: countersSig = datasetsResidual._replaceSigName(countersSig) self.eventCounterEmb = EventCounterMany(datasetsResidual.datasetsEmb, counters=counters, **kwargs) self.eventCounterSig = counter.EventCounter( datasetsResidual.datasetsSig, counters=countersSig, **kwargs) self.eventCounterSig.normalizeMCToLuminosity( datasetsResidual.datasetsEmb.getLuminosity())
def doCounters(datasets, massPoints): eventCounter = counter.EventCounter(datasets) eventCounter.normalizeMCByLuminosity() rows1 = [ "Trigger and HLT_MET cut", "taus == 1", "trigger scale factor", "electron veto", "muon veto", "njets", "MET" ] rows2 = [ "btagging scale factor", "deltaPhiTauMET<160", "deltaPhiTauMET<130", ] tableAll = eventCounter.getMainCounterTable() tableAll.keepOnlyRows(rows1+rows2) tableWH = counter.CounterTable() tableHH = counter.CounterTable() for mass in massPoints: tableWH.appendColumn(tableAll.getColumn(name="TTToHplusBWB_M%d"%mass)) tableHH.appendColumn(tableAll.getColumn(name="TTToHplusBHminusB_M%d"%mass)) tableWH2 = tableWH.clone() tableWH.keepOnlyRows(rows1) tableWH2.keepOnlyRows(rows2) tableHH2 = tableHH.clone() tableHH.keepOnlyRows(rows1) tableHH2.keepOnlyRows(rows2) format1 = counter.TableFormatText(counter.CellFormatTeX(valueFormat="%.0f", valueOnly=True)) format12 = counter.TableFormatText(counter.CellFormatTeX(valueFormat="%.1f", valueOnly=True)) format2 = counter.TableFormatText(counter.CellFormatTeX(valueFormat="%.2f", withPrecision=1)) print "tt -> bW bH+" print tableWH.format(format1) print tableWH2.format(format2) print print print "tt -> bH+ bH-" print tableHH.format(format12) print tableHH2.format(format2)
def doCounters(datasets): eventCounter = counter.EventCounter(datasets) eventCounter.normalizeMCByLuminosity() # eventCounter.normalizeMCToLuminosity(73) print "============================================================" print "Main counter (MC normalized by collision data luminosity)" mainTable = eventCounter.getMainCounterTable() # No uncertainties cellFormat = counter.TableFormatText(cellFormat=counter.CellFormatText( valueOnly=True)) print mainTable.format(cellFormat) print eventCounter.getSubCounterTable("b-tagging").format(cellFormat) print eventCounter.getSubCounterTable("Jet selection").format(cellFormat) print eventCounter.getSubCounterTable("Jet main").format(cellFormat)
def doCounters(myDsetMgr, mySuffix): eventCounter = counter.EventCounter(myDsetMgr) # append row from the tree to the main counter # eventCounter.getMainCounter().appendRow("MET > 70", treeDraw.clone(selection="met_p4.Et() > 70")) ewkDatasets = [ "WJets", "W1Jets", "W2Jets", "W3Jets", "W4Jets", "TTJets", "DYJetsToLL", "SingleTop", "Diboson" ] if mcOnly: eventCounter.normalizeMCToLuminosity(mcOnlyLumi) else: eventCounter.normalizeMCByLuminosity() print "============================================================" print mySuffix print "============================================================" print "Main counter (MC normalized by collision data luminosity)" mainTable = eventCounter.getMainCounterTable() mainTable.insertColumn( 2, counter.sumColumn( "EWKMCsum", [mainTable.getColumn(name=name) for name in ewkDatasets])) # Default # cellFormat = counter.TableFormatText() # No uncertainties cellFormat = counter.TableFormatText(cellFormat=counter.CellFormatText( valueOnly=False)) print mainTable.format(cellFormat) # print eventCounter.getSubCounterTable("tauIDTauSelection").format() print eventCounter.getSubCounterTable( "TauIDPassedEvt::TauSelection_HPS").format(cellFormat) print eventCounter.getSubCounterTable( "TauIDPassedJets::TauSelection_HPS").format(cellFormat) print eventCounter.getSubCounterTable("b-tagging").format(cellFormat) print eventCounter.getSubCounterTable("Jet selection").format(cellFormat) print eventCounter.getSubCounterTable("Jet main").format(cellFormat) print eventCounter.getSubCounterTable("VetoTauSelection").format( cellFormat) print eventCounter.getSubCounterTable("MuonSelection").format(cellFormat) print eventCounter.getSubCounterTable("MCinfo for selected events").format( cellFormat) print eventCounter.getSubCounterTable("ElectronSelection").format( cellFormat)
def printCounters(datasets): print "============================================================" print "Dataset info: " datasets.printInfo() eventCounter = counter.EventCounter(datasets) selection = "Sum$(%s) >= 1" % muonKinematics selection = "Sum$(%s && %s) >= 1" % (muonKinematics, muondB) selection = "Sum$(%s && %s && %s) >= 1" % (muonKinematics, muondB, muonIsolation) selection = "Sum$(%s && %s && %s) == 1" % (muonKinematics, muondB, muonIsolation) selection += "&&" + muonVeto selection += "&&" + electronVeto selection += "&&" + jetSelection eventCounter.getMainCounter().appendRow( "Selected control sample", treeDraw.clone(selection=selection)) eventCounter.normalizeMCByLuminosity() table = eventCounter.getMainCounterTable() mcDatasets = filter(lambda n: n != "Data", table.getColumnNames()) table.insertColumn( 1, counter.sumColumn("MCSum", [table.getColumn(name=name) for name in mcDatasets])) table.keepOnlyRows("Selected control sample") # reorder columns qcd = table.getColumn(name="QCD_Pt20_MuEnriched") table.removeColumn(table.getColumnNames().index("QCD_Pt20_MuEnriched")) table.insertColumn(5, qcd) table.transpose() # result = counter.CounterTable() # def addRow(name, value): # result.appendRow(counter.CounterRow(name, ["Number of events"], [value])) # for name in ["Data", "MCSum", "WJets", "TTJets", "DYJetsToLL", "QCD_Pt20_MuEnriched", "SingleTop", "Diboson"]: # addRow(name, table.getColumn(name=name).getCount(0)) cellFormat = counter.TableFormatText( counter.CellFormatTeX(valueFormat='%.1f')) print table.format(cellFormat)
def doCounters(datasets, ntupleCache): # Counters eventCounter = counter.EventCounter(datasets) mainCounter = eventCounter.getMainCounter(); counters = "counters/counter" if dataEra != "": counters = "counters/weighted/counter" mainCounter.appendRows(ntupleCache.histogram(counters)) format = counter.TableFormatText(counter.CellFormatText(valueFormat="%.0f")) table = mainCounter.getTable() print table.format(format) effFormat = counter.TableFormatText(counter.CellFormatText(valueFormat="%.2f", withPrecision=2)) teffs = mainCounter.constructTEfficiencies(createTEfficiency) table = counter.efficiencyTableFromTEfficiencies(teffs, mainCounter.getColumnNames(), rowNames) table.multiply(100) print table.format(effFormat)
def doCounters(datasets, datasetName, selectionName, ntupleCache): eventCounter = counter.EventCounter(datasets) def isNotThis(name): return name != datasetName eventCounter.removeColumns(filter(isNotThis, datasets.getAllDatasetNames())) counters = "counters/counter" if dataEra != "": counters = "counters/weighted/counter" eventCounter.getMainCounter().appendRows(ntupleCache.histogram(counters)) table = eventCounter.getMainCounterTable() nTauID = table.getCount(colName=datasetName, rowName="Tau ID").clone() nMuonIso = table.getCount(colName=datasetName, rowName="Muon isolation").clone() nIsoMuTrigger = table.getCount(colName=datasetName, rowName="IsoMu trigger").clone() eff = dataset.divideBinomial(nMuonIso, nTauID) effTrg = dataset.divideBinomial(nIsoMuTrigger, nMuonIso) out = StringIO.StringIO() out.write(table.format()) out.write("\n") out.write("Muon isolation/Tau ID = %.6f + %.6f - %.6f\n" % (eff.value(), eff.uncertaintyHigh(), eff.uncertaintyLow())) out.write( "IsoMu trigger/Muon isolation = %.6f + %.6f - %.6f\n" % (effTrg.value(), effTrg.uncertaintyHigh(), effTrg.uncertaintyLow())) print "Isolation mode", selectionName print out.getvalue() fname = "counters_muiso_" + selectionName + "_" + datasetName + ".txt" f = open(fname, "w") f.write(out.getvalue()) f.close() print "Printed tau counters to", fname out.close()
def doCounters(datasets): # Create EventCounter object, holds all counters of all datasets eventCounter = counter.EventCounter(datasets) # Normalize counters if mcOnly: eventCounter.normalizeMCToLuminosity(mcOnlyLumi) else: eventCounter.normalizeMCByLuminosity() # Create LaTeX format, automatically adjust value precision by uncertainty latexFormat = counter.TableFormatLaTeX( counter.CellFormatTeX(valueFormat="%.4f", withPrecision=2)) plainFormat = counter.TableFormatText( counter.CellFormatText(valueOnly=True)) #table = eventCounter.getMainCounterTable() #print table.format() table = eventCounter.getSubCounterTable("FullHiggsMassCalculator") #table.renameRows(counterLabels) print table.format(latexFormat)
def printCounters(datasets): eventCounter = counter.EventCounter(datasets) eventCounter.normalizeMCByLuminosity() ewkDatasets = ["WJets", "TTJets", "DYJetsToLL", "SingleTop", "Diboson"] print "============================================================" print "Main counter (MC normalized by collision data luminosity)" mainTable = eventCounter.getMainCounterTable() mainTable.insertColumn( 2, counter.sumColumn( "EWKMCsum", [mainTable.getColumn(name=name) for name in ewkDatasets])) # Default # cellFormat = counter.TableFormatText() # No uncertainties cellFormat = counter.TableFormatText(cellFormat=counter.CellFormatText( valueOnly=True)) print mainTable.format(cellFormat) print eventCounter.getSubCounterTable("MCinfo for selected events").format( cellFormat)
def printCounters(datasets): eventCounter = counter.EventCounter(datasets) eventCounter.normalizeMCByLuminosity() print "============================================================" print "Main counter (MC normalized by collision data luminosity)" print eventCounter.getMainCounterTable().format()